Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

NVM (Node Version Manager) Commands #234

Open Qingquan-Li opened 1 year ago

Qingquan-Li commented 1 year ago

Reference: https://github.com/nvm-sh/nvm

1. nvm install Node.js

To download, compile, and install the latest release of node, do this:

$ nvm install node # "node" is an alias for the latest version

To install a specific version of node:

$ nvm install 14.7.0 # or 16.3.0, 12.22.1, etc

The first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default).

To install the latest Node.js LTS version:

$ nvm install --lts
Installing latest LTS version.
...
Now using node v18.15.0 (npm v9.5.0)

2. Uninstall a Node.js Version

$ nvm uninstall 18.15.0
Uninstalled node v18.15.0

You may need to uninstall a Node.js version as root (on macOS):

$ sudo -s # root
Password:
# nvm uninstall 18.15.0
Uninstalled node v18.15.0
# exit
$

3. List Node.js Versions

If you want to see what versions are installed:

$ nvm ls
nvm ls
       v18.13.0
->     v18.15.0
         system
default -> node (-> v18.15.0)

If you want to see what versions are available to install:

$ nvm ls-remote

path to the executable to where it was installed:

$ nvm which 18.15
/Users/yourusername/.nvm/versions/node/v18.15.0/bin/node

4. Use a Different Node.js Version

$ nvm use system 
Now using system version of node: v16.16.0 (npm v8.16.0)

$ nvm ls        
       v18.13.0
       v18.15.0
->       system
default -> node (-> v18.15.0)
...

$ nvm use 18.15  
Now using node v18.15.0 (npm v9.5.0)