#中国大陆 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
4. 配置 npm 镜像
1
| npm config set registry https://registry.npmmirror.com
|
5. 安装 Codex CLI
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
| mkdir -p ~/.codex
cat <<EOF > ~/.codex/auth.json { "OPENAI_API_KEY": "sk-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 = "https://www.code.code/codex/v1"
[notice] hide_full_access_warning = true EOF
|
把 sk-key 和 base_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
| 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
source "$CONF_FILE"
|
8. 一键脚本(整块复制执行)
先把 OPENAI_API_KEY 和 CODEX_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
OPENAI_API_KEY="sk-key" CODEX_BASE_URL="https://www.code.code/codex/v1"
git clone https://gitee.com/mirrors/nvm.git ~/.nvm
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/
nvm install --lts
npm config set registry https://registry.npmmirror.com
npm i -g @openai/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
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
source "$CONF_FILE"
|