2024-06-01
温故知新
00
请注意,本文编写于 172 天前,最后修改于 172 天前,其中某些信息可能已经过时。

目录

简介
详细过程
执行一键安装脚本
解决
查看运行状态

简介

我的 Ubuntu 使用一键安装脚本安装 code-server 时,提示安装成功,但运行时报错:

sh
Failed to enable unit: Unit file code-server.service does not exist.

详细过程

执行一键安装脚本

运行指令:

sh
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run

运行后显示:

bash
Ubuntu 24.04 LTS Installing v4.89.1 of the amd64 deb package from GitHub. + mkdir -p ~/.cache/code-server + curl -#fL -o ~/.cache/code-server/code-server_4.89.1_amd64.deb.incomplete -C - https://github.com/coder/code-server/releases/download/v4.89.1/code-server_4.89.1_amd64.deb + mv ~/.cache/code-server/code-server_4.89.1_amd64.deb.incomplete ~/.cache/code-server/code-server_4.89.1_amd64.deb + sudo dpkg -i ~/.cache/code-server/code-server_4.89.1_amd64.deb 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

可以看到提示信息让运行 sudo systemctl enable --now code-server@$USER 启动 code-server ,但运行时会报错:

sh
# 运行 sudo systemctl enable --now code-server@$USER # 报错 Failed to enable unit: Unit file [email protected] does not exist. # 运行 sudo systemctl enable --now code-server # 报错 Failed to enable unit: Unit file code-server.service does not exist.

解决

尝试手动安装后不再报错:

sh
# 设置要安装的版本: export VERSION=4.89.1 # 运行 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 # 会输出 Created symlink /etc/systemd/system/default.target.wants/[email protected] → /usr/lib/systemd/system/[email protected].

然后运行:

sh
# 启动 sudo systemctl start code-server@$USER # 此时可能出现警告 Warning: The unit file, source configuration file or drop-ins of [email protected] changed on disk. Run 'systemctl daemon-reload' to reload units.

如果出现警告,则执行

sh
sudo systemctl daemon-reload # 然后再启动 sudo systemctl start code-server@$USER

查看运行状态

启动成功后,可以查看服务运行状态:

sh
sudo systemctl status code-server@$USER[email protected] - code-server Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled; preset: enabled) Active: active (running) since Sat 2024-06-01 13:56:36 UTC; 18min ago Main PID: 3698367 (node) Tasks: 22 (limit: 9352) Memory: 56.3M (peak: 72.6M) CPU: 1.469s CGroup: /system.slice/system-code\x2dserver.slice/[email protected] ├─3698367 /usr/lib/code-server/lib/node /usr/lib/code-server └─3698417 /usr/lib/code-server/lib/node /usr/lib/code-server/out/node/entry Jun 01 13:56:36 dddx-hp systemd[1]: Started [email protected] - code-server. Jun 01 13:56:36 dddx-hp code-server[3698367]: [2024-06-01T13:56:36.814Z] info Wrote default config file to /home/dddx/.config/code-server/config.yaml Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.231Z] info code-server 4.89.1 effc6e95b4ad1c5ac5f9083ec06663ba4a2e005c Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.233Z] info Using user-data-dir /home/dddx/.local/share/code-server Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info Using config file /home/dddx/.config/code-server/config.yaml Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info HTTP server listening on http://127.0.0.1:8080/ Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info - Authentication is enabled Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info - Using password from /home/dddx/.config/code-server/config.yaml Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info - Not serving HTTPS Jun 01 13:56:37 dddx-hp code-server[3698367]: [2024-06-01T13:56:37.246Z] info Session server listening on /home/dddx/.local/share/code-server/code-server-ipc.sock
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:DingDangDog

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!