安装VS Code 服务器运行版本
步骤:
-
安装 VS Code Server:
使用以下命令安装code-server
,它允许你在服务器上运行 VS Code,并通过浏览器访问:curl -fsSL https://code-server.dev/install.sh | sh
-
启动 VS Code Server:
启动code-server
:code-server
默认情况下,它会监听
127.0.0.1:8080
。 -
访问 VS Code:
打开浏览器并访问http://<server-ip>:8080
,它会要求你输入密码。默认密码可以在终端中找到。 -
设置密码和自定义配置:
为了增强安全性,建议设置密码。你可以通过编辑~/.config/code-server/config.yaml
文件来修改密码和端口:password: "your_password_here" bind-addr: "0.0.0.0:8080"
-
开机自启动:
创建一个新的服务文件:
sudo nano /etc/systemd/system/code-server.service
复制并粘贴以下内容(把 <your-username>
替换成你当前的用户名):
[Unit]
Description=code-server
After=network.target
[Service]
Type=simple
User=<your-username>
ExecStart=/usr/bin/code-server
Restart=on-failure
[Install]
WantedBy=multi-user.target
🔍 如果你的
code-server
不在/usr/bin/code-server
,可以通过which code-server
查到路径替换掉。
# 重新加载 systemd 配置
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
# 启动一次看看效果
sudo systemctl start code-server
# 设置开机自启
sudo systemctl enable code-server
sudo systemctl status code-server
如果输出是绿色 active (running)
,就说明已经配置好了。重启服务器后也会自动启动。
🧠 小提示
你可以自定义启动端口、工作目录、认证等,通过修改 ~/.config/code-server/config.yaml
:
bind-addr: 0.0.0.0:8080
auth: password
password: yourpassword
cert: false
修改后重启服务生效:
sudo systemctl restart code-server