在 Alibaba Cloud Linux 3.2104 LTS 64位 系统上安装浏览器,通常用于服务器环境,默认是不带图形界面(GUI)的,因此不能直接运行像 Chrome 或 Firefox 这样的桌面浏览器。但你可以根据使用场景选择以下几种方式:
✅ 场景一:需要图形界面 + 桌面浏览器(如 Chrome、Firefox)
如果你确实需要图形化浏览器(比如用于测试或远程桌面访问),你需要:
1. 安装图形界面(可选)
# 安装 GNOME 桌面环境(可选)
sudo dnf groupinstall "Server with GUI" -y
# 设置默认启动图形界面
sudo systemctl set-default graphical.target
sudo systemctl reboot
⚠️ 注意:云服务器一般不推荐开启 GUI,会占用资源且存在安全风险。
2. 安装桌面浏览器
方法 A:安装 Firefox(推荐,开源且支持良好)
sudo dnf install firefox -y
方法 B:安装 Google Chrome
# 下载并导入 Google 公钥
sudo rpm --import https://dl.google.com/linux/linux_signing_key.pub
# 添加 Chrome 的 YUM 源
sudo tee /etc/yum.repos.d/google-chrome.repo <<EOF
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub
EOF
# 安装 Chrome
sudo dnf install google-chrome-stable -y
安装完成后,可通过 VNC 或远程桌面连接使用图形界面启动浏览器。
✅ 场景二:无图形界面,仅命令行操作(推荐服务器用途)
如果你只是想从命令行“浏览网页”或下载内容,可以使用文本浏览器或命令行工具:
1. 安装文本浏览器(轻量高效)
-
w3m(支持表格、图片占位、颜色等)
sudo dnf install w3m w3m-img -y使用示例:
w3m https://www.aliyun.com -
lynx(最经典文本浏览器)
sudo dnf install lynx -y lynx https://www.baidu.com -
elinks
sudo dnf install elinks -y elinks https://example.com
2. 使用命令行工具获取网页内容
-
curl
curl -O https://example.com/page.html -
wget
wget https://example.com
这些工具适合自动化脚本、调试 API 或抓取数据。
✅ 场景三:运行无头浏览器(Headless Browser,用于爬虫/测试)
如果你想运行 Chrome/Firefox 在后台自动操作页面(如 Selenium 测试、截图、爬虫),可以使用 Headless 模式。
示例:使用 Chrome Headless
- 安装 Chrome(如上所示)
- 安装
chromedriver和 Python 工具(可选)
# 示例:用 Chrome 做一次无头截图
google-chrome --headless --disable-gpu --screenshot --no-sandbox https://www.aliyun.com
需要安装字体和依赖避免乱码:
sudo dnf install ipa-gothic-fonts xorg-x11-server-Xvfb -y
🔒 安全建议
- 不要在生产服务器上安装不必要的 GUI 和浏览器。
- 若必须使用浏览器,请限制权限,避免以 root 运行。
- 推荐使用容器(Docker)隔离浏览器环境。
总结
| 目的 | 推荐方案 |
|---|---|
| 图形化浏览网页 | 安装 GNOME + Firefox/Chrome(仅限测试) |
| 命令行查看网页 | w3m, lynx, elinks |
| 自动化/爬虫 | curl, wget, Chrome --headless |
| Selenium 测试 | Docker 中运行 Chrome Headless |
如有具体用途(如:部署自动化测试、查看日志页面、调试网页),欢迎补充,我可以提供更详细的配置方案。
CLOUD技术博