Ubuntu 22.04 安装 V2Ray 指南

在 Ubuntu 22.04 上从零安装 v2ray-core 5.53.0:官方安装脚本(install-release.sh 在线)与直接下载官方二进制 ZIP 两套方案,systemd 托管与验证回显、常见问题与卸载,全部命令已在 Ubuntu 22.04 LTS(x86_64)实测通过。

V2RayV2Ray2026/10/09

Ubuntu 22.04 安装 V2Ray 指南

目标:在 Ubuntu 22.04 LTS 上从零安装 v2ray-core(V2Fly 社区版代理内核),覆盖版本选型、官方安装脚本在线安装、直接下载官方二进制 ZIP 安装、基础配置、systemd 托管、启动验证、常见问题与卸载。全部命令与回显已在 Ubuntu 22.04 LTS(x86_64)实测通过(本文以 v2ray-core 5.53.0 为例)。

一、环境信息

项目值
操作系统Ubuntu 22.04.5 LTS(x86_64)
v2ray-core5.53.0(V2Fly,go1.26.1 linux/amd64)
官方维护V2Fly 社区(github.com/v2fly/v2ray-core)
安装路径/usr/local/bin/v2ray
配置文件/usr/local/etc/v2ray/config.json
数据文件/usr/local/share/v2ray/geoip.dat、geosite.dat
日志目录/var/log/v2ray/access.log、error.log
systemd 服务v2ray.service / v2ray@.service
默认监听127.0.0.1:1080(示例 socks)

⚠️ 注意:V2Ray 官方项目已停止维护,现由 V2Fly 社区接管并持续发布(版本号沿袭 v5.x)。本指南安装的即 V2Fly 发行的 v2ray-core,官方文档见 https://www.v2fly.org/。

二、版本选型说明

V2Ray 沿袭单一主版本线递进(无 LTS 分支),通过 GitHub Release 持续发布。版本仅需关注两个维度:

版本来源说明获取/查看命令
v2ray-core 二进制go1.26.1 编译,当前最新稳定为 5.53.0v2ray version

选型建议:

  • 服务器上优先用「官方安装脚本」或「直接下载二进制」,二者拿到的都是 GitHub 最新 Release(实测为 5.53.0),保障最新特性。
  • 版本号以 v2ray version 实际输出为准,本文不硬编码未来版本;升级只需覆盖 /usr/local/bin/v2ray 并重启服务。

三、方案 A:官方安装脚本在线安装(推荐)

3.1 前置依赖

官方脚本 install-release.sh 依赖 curl 与 unzip,需联网(可达 github.com)。依次安装:

apt-get update
apt-get install -y curl ca-certificates unzip

3.2 下载安装脚本

脚本来自 V2Fly 官方仓库 fhs-install-v2ray,master 分支为元数据文件(含 install-release.sh 文本内容),raw.githubusercontent.com 拉取:

curl -L -o install-release.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
head -3 install-release.sh

实测脚本头部:

#!/usr/bin/env bash
# shellcheck disable=SC2268

💡 说明:若 raw.githubusercontent.com 偶发连接重置,可用 github.com/v2fly/fhs-install-v2ray/raw/master/install-release.sh 作为备用地址,二者内容一致。

3.3 运行安装脚本

bash install-release.sh

实测完整回显(首次全新安装):

info: Installing V2Ray v5.53.0 for x86_64
Downloading V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v5.53.0/v2ray-linux-64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 18.4M  100 18.4M    0     0   963k      0  0:00:19  0:00:19 --:--:--  296k
Downloading verification file for V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v5.53.0/v2ray-linux-64.zip.dgst
info: Extract the V2Ray package to /tmp/tmp.ay48x9BAPX and prepare it for installation.
info: Systemd service files have been installed successfully!
warning: The following are the actual parameters for the v2ray service startup.
warning: Please make sure the configuration file path is correctly set.
# /etc/systemd/system/v2ray.service
[Unit]
Description=V2Ray Service
Documentation=https://www.v2fly.org/
After=network.target nss-lookup.target

[Service]
User=nobody
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/bin/v2ray run -config /usr/local/etc/v2ray/config.json
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/v2ray.service.d/10-donot_touch_single_conf.conf
# In case you have a good reason to do so, duplicate this file in the same directory and make your customizes there.
# Or all changes you made will be lost!  # Refer: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
[Service]
ExecStart=
ExecStart=/usr/local/bin/v2ray run -config /usr/local/etc/v2ray/config.json

installed: /usr/local/bin/v2ray
installed: /usr/local/share/v2ray/geoip.dat
installed: /usr/local/share/v2ray/geosite.dat
installed: /usr/local/etc/v2ray/config.json
installed: /var/log/v2ray/
installed: /var/log/v2ray/access.log
installed: /var/log/v2ray/error.log
installed: /etc/systemd/system/v2ray.service
installed: /etc/systemd/system/v2ray@.service
removed: /tmp/tmp.ay48x9BAPX
info: V2Ray v5.53.0 is installed.
You may need to execute a command to remove dependent software: apt purge curl unzip
Please execute the command: systemctl enable v2ray; systemctl start v2ray

脚本最后会提示:启动服务用 systemctl enable v2ray; systemctl start v2ray。

3.4 重复安装/升级的探测逻辑

当环境中已装同版本(或更新)时,脚本会做版本比对并跳过下载:

info: No new version. The current version of V2Ray is v5.53.0 .

即脚本通过读取本机 v2ray version 与远端 Release 版本做比较,已最新则直接结束。

四、方案 B:直接下载官方二进制 ZIP 安装(离线/可控版本)

适合内网隔离或需要精确锁定交旧版本升级时使用。核心就是拿官方发布的 v2ray-linux-64.zip 解压后安装到标准路径。

4.1 查看当前最新版本

通过 GitHub Release API 获取最新 tag(也可直接访问 Releases 页面人工确认):

curl -s https://api.github.com/repos/v2fly/v2ray-core/releases/latest
# 关注 "tag_name": "v5.53.0"

4.2 下载对应平台压缩包

Linux x86_64 对应 v2ray-linux-64.zip。直接取最新版本的固定下载地址:

cd /v2ray-bin   # 手动下载可任意放一目录,此处示例
curl -L -o v2ray-linux-64.zip https://github.com/v2fly/v2ray-core/releases/latest/download/v2ray-linux-64.zip

⚠️ 注意:该文件约 19MB,外网链路不稳定会中断。可用 curl -L -C - 断点续传(-C - 自动从已有字节续传),或循环重试直到 unzip -t 校验通过:

unzip -t v2ray-linux-64.zip   # 输出 "No errors detected in compressed data" 即为完整

实测成功回显:

    testing: vpoint_socks_vmess.json   OK
    testing: v2ray                    OK
No errors detected in compressed data of v2ray-linux-64.zip.

4.3 解压并查看内容

unzip -o v2ray-linux-64.zip
ls -l

实测目录内容(版本 5.53.0):

total 63548
-rw-r--r-- 1 root root     4220 Aug  2 22:49 config.json
-rw-r--r-- 1 root root   229155 Aug  2 22:49 geoip-only-cn-private.dat
-rw-r--r-- 1 root root 22765206 Aug  2 22:49 geoip.dat
-rw-r--r-- 1 root root  2270128 Aug  2 22:49 geosite.dat
drwxr-xr-x 3 root root     4096 Aug  2 22:49 systemd
-rwxr-xr-x 1 root root 39780478 Aug  2 22:49 v2ray
-rw-r--r-- 1 root root      391 Aug  2 22:49 vpoint_socks_vmess.json
-rw-r--r-- 1 root root      537 Aug  2 22:49 vpoint_vmess_freedom.json

其中:v2ray 为主程序,config.json 为带注释的示例配置,geoip.dat/geosite.dat 为路由数据,systemd/ 下为服务文件,vpoint_*.json 为示例服务端配置。

4.4 安装到标准路径

cp v2ray /usr/local/bin/v2ray
chmod +x /usr/local/bin/v2ray
cp geoip.dat geosite.dat /usr/local/share/v2ray/   # 需先 mkdir -p /usr/local/share/v2ray
mkdir -p /var/log/v2ray /usr/local/etc/v2ray
cp systemd/system/v2ray.service /etc/systemd/system/v2ray.service
cp systemd/system/v2ray@.service /etc/systemd/system/v2ray@.service

4.5 校验版本

v2ray version

实测回显:

V2Ray 5.53.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.26.1 linux/amd64)
A unified platform for anti-censorship.

五、多方案对比与选择建议

维度方案 A(官方脚本)方案 B(二进制 ZIP)
是否需联网需(github.com)需;离线可预下载后拷贝
版本来源自动取 GitHub 最新 Release自选 tag,可控/可固定
安装步数一条命令下载+解压+手动安装
systemd 服务自动安装需手动拷贝服务文件
数据文件自动安装 geoip/geosite需手动拷贝
适用场景首选、可联网服务器内网隔离、锁定版本、二进制升级

选择建议:可联网环境直接用方案 A;需要锁定精确版本、离线分发或仅更新二进制时用方案 B(覆盖 /usr/local/bin/v2ray 后 systemctl restart v2ray 即可完成升级)。

六、配置说明

安装后默认配置文件为 /usr/local/etc/v2ray/config.json,两套方案生成的最小配置相同:

{}

空配置即可被成功解析并由 systemd 启动(无任何 inbound),但要真正提供代理需补齐 inbound/outbound。以下为最小可用配置(监听 127.0.0.1:1080 的 Socks5,出口直连):

{
  "log": { "loglevel": "info" },
  "inbounds": [
    {
      "port": 1080,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "settings": { "udp": true }
    }
  ],
  "outbounds": [
    { "protocol": "freedom" }
  ]
}

💡 说明:配置放在 /usr/local/etc/v2ray/config.json;数据文件 geoip.dat/geosite.dat 位于 /usr/local/share/v2ray/。系统通过 v2ray.location.asset 环境变量定位数据文件目录,默认即二进制目录与上述标准路径。

详细参数(inbounds/outbounds/routing/dns/log/policy/api)见《V2Ray 配置参数详解》。

七、systemd 托管

7.1 服务文件

方案 A 自动安装;方案 B 需手动拷贝。服务文件关键行为(Ubuntu 实测):

  • 以 nobody 用户运行;
  • CapabilityBoundingSet/AmbientCapabilities 仅保留 CAP_NET_ADMIN CAP_NET_BIND_SERVICE(绑定 1024 以下端口与网络管理能力);
  • NoNewPrivileges=true;
  • Restart=on-failure(失败自动重启,退出码 23 除外);
  • 单实例用 v2ray.service,多实例用模板单元 v2ray@.service(%i 对应 /usr/local/etc/v2ray/<实例名>.json)。

7.2 启用与启动

systemctl daemon-reload
systemctl enable v2ray
systemctl start v2ray

实测 enable 回显:

Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.

7.3 状态查看

systemctl status v2ray --no-pager
systemctl is-active v2ray

实测回显:

● v2ray.service - V2Ray Service
     Loaded: loaded (/etc/systemd/system/v2ray.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/v2ray.service.d
             └─10-donot_touch_single_conf.conf
     Active: active (running) since Fri 2026-10-09 02:31:25 UTC; 1min 52s ago
       Docs: https://www.v2fly.org/
   Main PID: 2940 (v2ray)
      Tasks: 9 (limit: 8648)
     Memory: 13.7M
        CPU: 57ms

is-active 返回:

active

7.4 查看日志

journalctl -u v2ray --no-pager -n 6

实测回显:

Oct 09 02:31:25 host systemd[1]: Started V2Ray Service.
Oct 09 02:31:25 host v2ray[2940]: V2Ray 5.53.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.26.1 linux/amd64)
Oct 09 02:31:25 host v2ray[2940]: A unified platform for anti-censorship.
Oct 09 02:31:25 host v2ray[2940]: 2026/10/09 02:31:25 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080
Oct 09 02:31:25 host v2ray[2940]: 2026/10/09 02:31:25 [Info] transport/internet/udp: listening UDP on 127.0.0.1:1080
Oct 09 02:31:25 host v2ray[2940]: 2026/10/09 02:31:25 [Warning] V2Ray 5.53.0 started

八、直接启动验证

不经过 systemd,前台直接启动便于排障:

v2ray run -c /usr/local/etc/v2ray/config.json

实测回显(Socks5 + freedom 配置):

V2Ray 5.53.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.26.1 linux/amd64)
A unified platform for anti-censorship.
2026/10/09 02:31:05 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:1080
2026/10/09 02:31:05 [Info] transport/internet/udp: listening UDP on 127.0.0.1:1080
2026/10/09 02:31:05 [Warning] V2Ray 5.53.0 started

配置校验(只校准配置不启动):

v2ray test -c /usr/local/etc/v2ray/config.json

实测回显末两行:

V2Ray 5.53.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.26.1 linux/amd64)
A unified platform for anti-censorship.
Configuration OK.

九、注意事项

  • 服务文件里的 User=nobody:nobody 用户需能读取配置目录。若你的 config.json 放置在权限受限的自定义路径,需调整 User= 或目录权限,否则启动报 permission denied。
  • 默认只监听 127.0.0.1:示例配置监本机回环,仅本机可用。要对外提供服务,把 listen 改为 0.0.0.0 并在防火墙放行对应端口(以示例 socks 端口为例 ufw allow 1080/tcp)。
  • 账号/密钥:VMess 用户 id 用 UUID(v2ray uuid 生成),TLS 证书用 v2ray tls cert 生成,切勿写入明文密码类占位符。
  • systemctl 每行仅操作一个单元:enable/start/stop/restart 每行只写一个服务名,勿在一行堆多个。
  • 升级:方案 B 直接覆盖 /usr/local/bin/v2ray 后 systemctl restart v2ray;方案 A 重跑 install-release.sh 即可。
  • 降级:从 GitHub Releases 选旧 tag,用方案 B 手动覆盖降级。

十、常见问题(FAQ)

Q1:v2ray run 报 invalid field rule / failed to open file: geoip.dat?

原因:配置引用了 geoip:private 等路由规则但本机缺少数据文件。解决:把 zip 里的 geoip.dat 放到 v2ray.location.asset 指向目录(标准即 /usr/local/share/v2ray/),或临时 export "v2ray.location.asset=/usr/local/share/v2ray/"。

Q2:v2ray test 报 unknown config id: bogus?

这是 v2ray test 的合法报错示例,说明配置里 inbound protocol 填了内核不认识的值。核对 protocol 是否属于 vmess/vless/trojan/shadowsocks/socks/http/dokodemo-door 等可识别协议。

Q3:bind 端口小于 1024 失败?

若在 /usr/local/etc/v2ray/config.json 中把 inbound port 设为 <1024,虽然服务保留了 CAP_NET_BIND_SERVICE 能力可绑定,但受 User=nobody 与内核能力边界影响可能报错。建议改用非特权端口(≥1024);确需 80/443 做 TLS 入口时,改用非 root 的端口转发或调整能力配置。

Q4:能否多实例(多端口多配置)?

可以。用模板单元 v2ray@<实例名>,每个实例对应一个 /usr/local/etc/v2ray/<实例名>.json。例如 systemctl start v2ray@myproxy。注意每行仅操作一个实例。

十一、卸载方式

systemctl disable v2ray
systemctl stop v2ray
rm -f /usr/local/bin/v2ray
rm -f /etc/systemd/system/v2ray.service /etc/systemd/system/v2ray@.service
rm -rf /etc/systemd/system/v2ray.service.d
rm -rf /usr/local/etc/v2ray
rm -rf /usr/local/share/v2ray
rm -rf /var/log/v2ray
systemctl daemon-reload

实测 disable 回显:

Removed /etc/systemd/system/multi-user.target.wants/v2ray.service.

💡 说明:方案 A 安装时依赖 curl unzip,如需一并清理可执行 apt purge curl unzip(脚本末尾亦如此提示)。

十二、参考链接