How to Install the Gemini CLI on Ubuntu by Upgrading Node.js

Daily log

I installed the Gemini CLI because I want to ask an AI questions without leaving my terminal. The installation requires Node.js v20 or newer, so I chose to install version 22, as it is the latest Long-Term Support (LTS) release, ensuring stability. Since the Node.js version in Ubuntu’s official repository is older, I had to add a new repository to install it.

Here are the detailed steps I took to get it working:

1. Remove the old Node.js version

First, you need to remove the outdated Node.js package that was installed from Ubuntu’s default repositories.

sudo apt remove nodejs

Running sudo apt autoremove afterward is also a good idea to clean up any leftover dependencies.

2. Add the NodeSource repository for Node.js v22

I followed the official instructions from the NodeSource distributions page, which you can find here: https://nodesource.com/products/distributions.

First, to download their setup script, you need the curl command. It’s best to make sure it’s installed.

sudo apt-get install -y curl

Now, use curl to download and run the NodeSource setup script for the Node.js v22 LTS release. This will configure apt to use the NodeSource repository.

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -

3. Install Node.js v22 from NodeSource

Now that apt is configured to use the new repository, you can install the Node.js v22 package. The -y flag automatically confirms the installation.

sudo apt-get install -y nodejs

After this step, you can verify the installation by checking the version: node -v. It should show a version number starting with “v22”.

4. Install the Gemini CLI

Finally, with the correct LTS version of Node.js installed, you can use npm (Node Package Manager) to install the Gemini CLI. The -g flag installs the package globally, which requires administrator permissions, so you need to use sudo.

sudo npm install -g @google/gemini-cli

Conclusion

Before installing the CLI, I always felt it was inefficient to switch from the terminal to another window just to ask the AI a question. That feeling is now gone. I feel much more comfortable now that I can complete all of my work, including research and asking questions, without ever leaving the command line. It has resolved a frustrating part of my workflow.

Daily log programming
potatomatoes167をフォローする
アサボリアンのBLOG

コメント

タイトルとURLをコピーしました