Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update node version on Google Cloud Shell

I'm using Google Cloud Shell, and the default node version is 12.14.1. Is there an easy way to update the node version to 14.x or 16.x?

node seems to be installed with nvm

$ which node
/usr/local/nvm/versions/node/v12.14.1/bin/node
like image 726
Tri Nguyen Avatar asked Sep 14 '26 17:09

Tri Nguyen


2 Answers

Apparently one can simply use nvm command to change the version. When I tried:

nvm install 14

I was upgraded to 14. I think I can install/change my node versions as desired.

like image 129
Kolban Avatar answered Sep 16 '26 06:09

Kolban


nvm isn't a file, but a bash function and is exposed via /google/devshell/bashrc.google.d/nvm.

This script is sourced by default by /google/devshell/bashrc.google. However, I inadvertently commented out these lines, which disabled it

if [ -f "/google/devshell/bashrc.google" ]; then
  source /google/devshell/bashrc.google
fi

For anyone who's curious, those lines are put in there by /etc/profile.d/restore_bashrc.sh.

If you ran into a similar issue and want to fix it manually, you can add the following lines to your .bashrc

for FILE in /google/devshell/bashrc.google.d/*; do
  if [ -f "$FILE" ]; then
    source "$FILE"
  fi
done
like image 44
Tri Nguyen Avatar answered Sep 16 '26 05:09

Tri Nguyen