Skip to content

中国大陆 nvm 安装与 Codex 配置

#中国大陆 nvm 安装与 Codex 配置

1. 安装 nvm

1
git clone https://gitee.com/mirrors/nvm.git ~/.nvm

2. 当前终端加载 nvm(临时生效)

1
2
3
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export NVM_NODEJS_ORG_MIRROR=https://mirrors.ustc.edu.cn/node/

3. 安装 Node LTS

1
nvm install --lts

4. 配置 npm 镜像

1
npm config set registry https://registry.npmmirror.com

5. 安装 Codex CLI

1
npm i -g @openai/codex

6. 配置 Codex

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1) 确保目录存在
mkdir -p ~/.codex

# 2) 写入 auth.json (API Key)
cat <<EOF > ~/.codex/auth.json
{
"OPENAI_API_KEY": "sk-key"
}
EOF

# 3) 写入 config.toml
cat <<EOF > ~/.codex/config.toml
disable_response_storage = true
model = "gpt-5.2-codex"
model_provider = "custom"
model_reasoning_effort = "xhigh"
sandbox_mode = "danger-full-access"
approval_policy = "never"
personality = "pragmatic"

[model_providers.custom]
name = "custom"
wire_api = "responses"
requires_openai_auth = true
base_url = "https://www.code.code/codex/v1"

[notice]
hide_full_access_warning = true
EOF

sk-keybase_url 换成你自己的值。

7. 写入 Shell 配置(永久生效)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 1) 自动探测 Shell 配置文档
if [ -n "$ZSH_VERSION" ]; then
CONF_FILE="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ]; then
CONF_FILE="$HOME/.bashrc"
else
# 如果无法识别,默认尝试 .profile
CONF_FILE="$HOME/.profile"
fi

echo "检测到配置文档路径: $CONF_FILE"

# 2) 将 NVM 配置追加到文档中
cat <<EOF >> "$CONF_FILE"

# >>> NVM & Node Mirror Config >>>
export NVM_DIR="\$HOME/.nvm"
[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"
export NVM_NODEJS_ORG_MIRROR=https://mirrors.ustc.edu.cn/node/
# <<< END <<<
EOF

# 3) 立即让当前窗口生效
source "$CONF_FILE"

8. 一键脚本(整块复制执行)

先把 OPENAI_API_KEYCODEX_BASE_URL 改成你自己的值,再整块复制执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
set -e

# 0) 先改成你自己的值
OPENAI_API_KEY="sk-key"
CODEX_BASE_URL="https://www.code.code/codex/v1"

# 1) 安装 nvm
git clone https://gitee.com/mirrors/nvm.git ~/.nvm

# 2) 当前终端加载 nvm + Node 镜像
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
export NVM_NODEJS_ORG_MIRROR=https://mirrors.ustc.edu.cn/node/

# 3) 安装 Node LTS
nvm install --lts

# 4) 配置 npm 镜像
npm config set registry https://registry.npmmirror.com

# 5) 安装 Codex CLI
npm i -g @openai/codex

# 6) 配置 Codex
mkdir -p ~/.codex
cat <<EOF > ~/.codex/auth.json
{
"OPENAI_API_KEY": "$OPENAI_API_KEY"
}
EOF

cat <<EOF > ~/.codex/config.toml
disable_response_storage = true
model = "gpt-5.2-codex"
model_provider = "custom"
model_reasoning_effort = "xhigh"
sandbox_mode = "danger-full-access"
approval_policy = "never"
personality = "pragmatic"

[model_providers.custom]
name = "custom"
wire_api = "responses"
requires_openai_auth = true
base_url = "$CODEX_BASE_URL"

[notice]
hide_full_access_warning = true
EOF

# 7) 写入 Shell 配置(永久生效)
if [ -n "$ZSH_VERSION" ]; then
CONF_FILE="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ]; then
CONF_FILE="$HOME/.bashrc"
else
CONF_FILE="$HOME/.profile"
fi

echo "检测到配置文档路径: $CONF_FILE"

cat <<EOF >> "$CONF_FILE"

# >>> NVM & Node Mirror Config >>>
export NVM_DIR="\$HOME/.nvm"
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
export NVM_NODEJS_ORG_MIRROR=https://mirrors.ustc.edu.cn/node/
# <<< END <<<
EOF

# 8) 立即让当前窗口生效
source "$CONF_FILE"

About this Post

This post is written by KaranocaVe.

#nvm #Node.js #npm #镜像 #Codex