如何在各种环境中安装code-server:完整指南
code-server 项目地址: https://gitcode.com/gh_mirrors/cod/code-server
code-server是一个允许你在任何地方通过浏览器访问VS Code的强大工具。本文将详细介绍在各种操作系统和Linux发行版上安装code-server的多种方法。
一、安装脚本(推荐方法)
对于大多数用户来说,使用官方提供的安装脚本是最简单快捷的方式。这个脚本会自动检测你的系统环境并选择最适合的安装方式。
安装步骤:
- 首先可以预览安装过程(不实际执行):
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
- 实际安装命令:
curl -fsSL https://code-server.dev/install.sh | sh
常用参数说明:
--method
:指定安装方式(detect/standalone)--prefix
:指定安装路径(默认为~/.local)--version
:安装特定版本--edge
:安装最新的预发布版本
安装完成后,脚本会显示如何运行和启动code-server的说明。
二、不同系统的安装方法
1. Debian/Ubuntu系统
# 下载.deb包
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
# 安装
sudo dpkg -i code-server_${VERSION}_amd64.deb
# 启用服务
sudo systemctl enable --now code-server@$USER
2. RHEL/CentOS/Fedora系统
# 下载.rpm包
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server-$VERSION-amd64.rpm
# 安装
sudo rpm -i code-server-$VERSION-amd64.rpm
# 启用服务
sudo systemctl enable --now code-server@$USER
3. Arch Linux系统
可以通过AUR仓库安装:
yay -S code-server
sudo systemctl enable --now code-server@$USER
4. macOS系统
使用Homebrew安装:
brew install code-server
brew services start code-server
三、其他安装方式
1. 使用npm安装
适合以下场景:
- 非amd64/arm64架构
- Windows系统
- 旧版glibc系统
安装命令:
npm install --global code-server
2. 独立版本安装
下载对应平台的.tar.gz压缩包,解压后即可运行:
mkdir -p ~/.local/lib ~/.local/bin
curl -fL https://github.com/coder/code-server/releases/download/v$VERSION/code-server-$VERSION-linux-amd64.tar.gz | tar -C ~/.local/lib -xz
mv ~/.local/lib/code-server-$VERSION-linux-amd64 ~/.local/lib/code-server-$VERSION
ln -s ~/.local/lib/code-server-$VERSION/bin/code-server ~/.local/bin/code-server
3. Docker方式运行
docker run -it --name code-server -p 127.0.0.1:8080:8080 \
-v "$HOME/.local:/home/coder/.local" \
-v "$HOME/.config:/home/coder/.config" \
-v "$PWD:/home/coder/project" \
-u "$(id -u):$(id -g)" \
-e "DOCKER_USER=$USER" \
codercom/code-server:latest
四、特殊平台安装
1. Raspberry Pi
建议使用npm方式安装:
npm install --global code-server
2. Windows系统
目前没有官方发布的Windows版本,建议使用npm安装。
3. Termux环境
请参考专门的Termux安装文档。
五、卸载code-server
1. 通用卸载方法
删除配置和数据目录:
rm -rf ~/.local/share/code-server ~/.config/code-server
2. 按安装方式卸载
- 脚本安装:
rm -rf ~/.local/lib/code-server-*
- Homebrew安装:
brew uninstall code-server
- npm安装:
npm uninstall --global code-server
- Debian/Ubuntu:
sudo apt remove code-server
六、安装后的使用
无论采用哪种安装方式,安装完成后:
- 访问 http://127.0.0.1:8080
- 密码存储在 ~/.config/code-server/config.yaml 文件中
通过本文介绍的各种方法,你应该能够在任何主流操作系统上成功安装和使用code-server,享受远程编码的便利。
code-server 项目地址: https://gitcode.com/gh_mirrors/cod/code-server
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考