Ubuntu 24.04 安装配置 vscode-server

Ubuntu 24.04 安装配置 vscode-server

一、安装

bash 复制代码
# 更新系统
sudo apt update && sudo apt upgrade -y

# 官方脚本一键安装
curl -fsSL https://code-server.dev/install.sh | sh

# 查看版本
code-server --version

执行结果

bash 复制代码
deb package has been installed.

To have systemd start code-server now and restart on boot:
  sudo systemctl enable --now code-server@$USER
Or, if you don't want/need a background service you can run:
  code-server

Deploy code-server for your team with Coder: https://github.com/coder/coder

二、修改配置

bash 复制代码
# 编辑配置文件
nano ~/.config/code-server/config.yaml

配置内容(直接替换):

yaml 复制代码
bind-addr: 0.0.0.0:8080
auth: password
password: 自定义密码

三、启动并设置开机自启

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl enable --now code-server@$USER

# 查看运行状态
sudo systemctl status code-server@$USER

执行结果

bash 复制代码
Created symlink /etc/systemd/system/default.target.wants/code-server@ubuntu.service → /usr/lib/systemd/system/code-server@.service.

四、防火墙放行端口

bash 复制代码
sudo ufw allow 8080

五、访问

浏览器打开:

复制代码
http://服务器IP:8080

输入配置的密码登录即可。

六、常用服务命令

bash 复制代码
# 重启
sudo systemctl restart code-server@$USER
# 停止
sudo systemctl stop code-server@$USER
# 查看状态
sudo systemctl status code-server@$USER

端口检查(验证 8080 端口是否监听)

bash 复制代码
# 方式1:查看端口监听状态
ss -tlnp | grep 8080

# 方式2:curl验证端口可访问性
curl -i http://localhost:8080  # 如果绑定到 localhost

addr=$(grep -E '^\s*bind-addr' /home/$USER/.config/code-server/config.yaml | cut -d ':' -f 2- | tr -d ' ')
curl -i http://${addr} # 验证(在目标主机上)

七、 手动下载 deb 包 + apt 修复依赖(适合网络受限)

直接下载 deb 包安装,用 apt 修复依赖,无需配置仓库但需手动更新版本。

复制代码
# 1. 安装依赖
sudo apt update && sudo apt install -y curl
 
# 2. 下载最新版 deb 包(替换 VERSION 为实际版本,如 4.23.0)
VERSION="4.23.0"
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
 
# 3. 安装 deb 包
sudo dpkg -i code-server_${VERSION}_amd64.deb
 
# 4. 修复依赖
sudo apt -f install -y
 
# 5. 启用服务(可选)
sudo systemctl enable --now code-server@$USER

八、 卸载方法

bash 复制代码
sudo apt remove -y code-server
sudo apt autoremove -y
sudo rm -rf /etc/apt/sources.list.d/coder.list /etc/apt/trusted.gpg.d/coder.gpg
rm -rf ~/.config/code-server

ref: https://developer.aliyun.com/article/1688553

相关推荐
|晴 天|2 小时前
Vue 3 + TypeScript + Element Plus 博客系统开发总结与思考
前端·vue.js·typescript
猫3282 小时前
v-cloak
前端·javascript·vue.js
旷世奇才李先生3 小时前
Vue 3\+Vite\+Pinia实战:企业级前端项目架构设计
前端·javascript·vue.js
SoaringHeart4 小时前
Flutter进阶:用OverlayEntry 实现所有弹窗效果
前端·flutter
闫利朋5 小时前
Ubuntu 24.04 桌面安装向日葵完整指南
linux·运维·ubuntu
IT_陈寒6 小时前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace6 小时前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常6 小时前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o6 小时前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端7 小时前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试