先安装node.js,要求大于20

有两种安装方式,一种直接在系统安装,另一种是通过nvm安装。通过nvm安装node.js之后一般也是用nvm的npm了,不用系统的npm。

系统安装node.js

 curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
 sudo apt install -y nodejs
 node -v

或者用nvm安装node.js

# 查看当前系统的node.js版本
node -v

# 安装nvm
sudo apt remove -y nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc

# 安装新 Node
nvm install 20
nvm use 20
nvm alias default 20

用npm安装 gemini-cli

# 先查看npm是用的系统的还是nvm下的,如果用nvm安装的node.js,大概率以及换成了nvm下的
which npm

# 如果使用nvm下的npm进行安装就不用sudo
npm install -g @google/gemini-cli
# 如果之前安装过,想更新到最新版
npm install -g @google/gemini-cli@latest

# 如果是用系统下的npm安装就要用sudo
# -E 会保留:http_proxy,https_proxy
sudo -E npm install -g @google/gemini-cli

# 卸载 gemini-cli
sudo npm uninstall -g @google/gemini-cli

系统的npm一般在:

/usr/bin/npm -v
# 或
/usr/local/bin/npm -v

查一下系统是否还有 node 相关包记录(apt 系统)

dpkg -l | grep -E 'nodejs|npm'

Gemini CLI 安装和使用教程(新手入门指南)

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐