1. 先检测node.js版本,检查是否是否符合gemini_cli支持的版本
node -v
问题:如果不支持,安装gemini_cli会提示下面这样的错误,可以去官网nodejs.org/zh-cn/downl… 升级最新稳定版本。
...AppData/Roaming/npm/node_modules/@google/gemini-cli/node_modules/string-width/index.js:16 const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Mark}|\p{Surrogate})+$/v; ^ SyntaxError: Invalid regular expression flags at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:116:18) at ESMLoader.moduleProvider (node:internal/modules/esm/loader:218:14)
2. 安装gemini_cli
npm install -g @google/gemini-cli
3. 安装完成之后,使用gemini可以进入到操作界面
gemini
4. 首次进入界面,会提示选择,可以选择 Gemini API Key,需要去aistudio.google.com/api-keys 生成
5. 开始配置key,在系统环境变量-用户变量新增变量
还可以配置
set GEMINI_API_KEY="" //你的key
6. 配置完成之后,关闭终端,重新开启就可以使用了。
问题:但是当你尝试使用的时候,你会发现提示错误
[API Error: exception TypeError: fetch failed sending request]
这是因为gemini_cli不会自动代理,需要你手动。
这里有解决方法。blog.csdn.net/weiqule/art…
也可以继续看下去。 找到对应的文件
C:\Users\你的用户名\AppData\Roaming\npm\node_modules\@google\gemini-cli\dist\index.js
在终端安装
npm install -g undici
然后再找到的文件中的文件上加入
import { setGlobalDispatcher, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent({ uri: new URL('http://127.0.0.1:7890').toString() }); // 7890 是你本地代理端口,按需修改
setGlobalDispatcher(dispatcher);
然后就可以正常使用了。