1448

I have installed nvm (ubuntu with zsh shell) with two node version: v6.11.5 and v9.0.0 and the default version in nvm is the v9.0.0

Every time I need to change the node version

$ nvm list
         v6.11.5
->       v9.0.0
         system
default -> node (-> v9.0.0)
node -> stable (-> v9.0.0) (default)
stable -> 9.0 (-> v9.0.0) (default)


$ nvm v6

How could I change the nvm version default to define v6.11.5?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Pablo Ezequiel Inchausti
  • 16,623
  • 7
  • 28
  • 42

27 Answers27

2956

(nvm maintainer here)

nvm alias default 6.11.5 if you want it pegged to that specific version.

You can also do nvm alias default 16 or nvm alias default node.

Either way, you'll want to upgrade to the latest version of nvm (v0.39.2 as of this writing)

# nvm set default node.js version 16.14.2
$ nvm alias default 16.14.2
$ nvm use

$ node -v
# v16.14.2
LJHarb
  • 32,486
  • 2
  • 32
  • 38
  • 1
    Addition: alias works as long as you're not installing new versions. After installing a new node the node will be your current node to use. So if you want to prevent this behavior you have to explicitly set up nvm alias default desiredVersionOfNode after each installation or just reopen a terminal. – daGo Sep 22 '19 at 05:39
  • 127
    Use `nvm alias default node` to make the "latest" the default. – Ryan Wheale Mar 24 '20 at 21:35
  • Is anyone else finding that "nvm alias default 10.17.0" isn't recognised as a command ? nvm just gives me a list of available options... it just doesn't seem to do anything (and my "ng -v" continues to use the wrong, older, version of node.js) – Mike Gledhill Mar 27 '20 at 10:13
  • @MikeGledhill are you sure you're using nvm proper? If you're using `nvm-windows`, that's an entirely different project. Actual `nvm` requires WSL to work on windows. – LJHarb Mar 28 '20 at 21:25
  • 58
    Doing `nvm alias default` doesn't do anything. The tag "default" changes, but a new shell is still using the not-desired-version. I found that uninstalling not needed versions works. – Jari Turkia May 29 '20 at 06:30
  • 1
    nvm alias default v12.13.1 not set the version as default – sejn Jun 08 '20 at 13:14
  • 17
    `nvm alias default node` to use the latest version of Node installed on your computer. Remember to use `nvm use node` (or whatever Node version you want to use) after the first command to actually change the version. My example (I was using version 13 as default, but having 15 on machine and wanting to set default to latest version of Node): `nvm alias default node` `nvm use node` was like using (in my case): `nvm alias default 15` `nvm use 15` – mold Apr 07 '21 at 17:15
  • 1
    That's right, then you can do afterwards: nvm use default – Konkret Jul 06 '21 at 12:29
  • Make sure to quit the Terminal and reopen – Lahiru Pinto Sep 09 '21 at 06:25
  • 13
    Might want to just use the latest long-term stable release. `nvm alias default lts/*` – dijonkitchen Sep 16 '21 at 14:25
  • 1
    I seem to need to run `nvm use default` in my `~/.bashrc` file in order to get this to work. – PatS Dec 09 '21 at 19:07
  • I'm using zsh, I also had to add `nvm use default > /dev/null` to my ~/.zprofile – garryp Apr 04 '22 at 13:17
  • For paranoid double-checking: I always open a new terminal windows/tab thereaftert, and truly verify with `nvm list` (looking at both `-->` (current version) and `default -->` (default version indeed) as well as `node -v` of course. – Frank N May 26 '22 at 19:49
  • @LJHarb So one question I have, when I download node by means other than nvm... They go to my `/user/local/bin/node` & `/user/local/bin/npm` (The "system copy"). Since nvm downloads them to `.nvm/versions/node`, do I need to keep the "system copy" that is in `/user/local/bin` or can I delete it? – Nate Thompson Jun 24 '22 at 19:58
  • @NateThompson that's up to you! You can certainly keep it, or delete it, as you like. – LJHarb Jun 25 '22 at 20:51
  • I am on version `0.39.1` of nvm, and you should run `nvm use default` **after** you have run `nvm alias default v14.7.0`, for example. Thanks. – BenHerbert Aug 08 '22 at 10:37
  • Your answer is checked as the accepted answer so please update it with the info from the comments because it is incomplete as it is and will confuse people who come here for an answer that works. – user281681 Nov 16 '22 at 12:56
  • 1
    @user281681 if you mean, add "nvm use", i've just done that. – LJHarb Nov 17 '22 at 18:23
  • Not sure if "nvm use" will work, but I usually put the version after it, like ```nvm use 18.12.1``` or ```nvm use default```. It's clear and avoids you making an easy mistake. – user281681 Nov 18 '22 at 08:19
  • 3
    `nvm use` with no arguments will use whatever's in `.nvmrc`. – LJHarb Nov 19 '22 at 22:12
  • If you set the PATH which includes the node path in your shell profile like `.zhrc`, `.bash_profile`, etc, you need to update it to the version you want to use. So then whenever you open a new shell session, it will points to the correct version. – Yan Yan Aug 16 '23 at 21:47
  • `nvm use default` will do the job. Just `nvm use` is gonna find the `.nvmrc` in root and use the version set there, or will error out with `no .nvmrc found` – Abhijeet Khangarot Aug 29 '23 at 02:19
190

Lets say to want to make default version as 10.19.0.

nvm alias default v10.19.0

But it will give following error

! WARNING: Version 'v10.19.0' does not exist.
default -> v10.19.0 (-> N/A)

In That case you need to run two commands in the following order

# Install the version that you would like 
nvm install 10.19.0

# Set 10.19.0 (or another version) as default
nvm alias default 10.19.0
Dipesh Yadav
  • 2,353
  • 1
  • 14
  • 9
138

This will set the default to be the most current version of node

nvm alias default node

and then you'll need to run

nvm use default

or exit and open a new tab

alltozall20381
  • 1,425
  • 1
  • 4
  • 2
  • 2
    Asked for node 6, your solution will choose the last node stable version to use. So it will not use specific 6 version – MathKimRobin Sep 09 '20 at 21:52
  • 1
    Even though this is pretty useful, this doesn't answer the question at all. – ljleb Feb 15 '21 at 13:38
  • This gave me a message "Your user’s .npmrc file (${HOME}/.npmrc) has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm. Run `nvm use --delete-prefix v15.13.0` to unset it." I ended up running the suggested command and it worked. – Nic Scozzaro Apr 01 '21 at 05:50
  • 1
    Yours is the first answer that tells me to run `nvm use default` which is what I was missing. – MrE Oct 25 '21 at 20:56
  • 1
    This works for me, but only in the same shell. When I open a new one `node -v` still prints the previous version... – Moritz Feb 27 '23 at 08:02
  • You can add `nvm use default` to your `.zshrc` or `.bashrc` file to persist across terminal sessions. – ksingh Jun 12 '23 at 19:06
  • Still working with node.js version 16 LTS and 18 LTS. Put the alias name first with the version you want to make it default, and then run nvm use "alias name (default)" – TheScripterX Aug 20 '23 at 08:43
68

If you want to switch only for once use this

nvm use 12.x

Else if you want to switch the default node version then use

nvm use default 12.x 

or

nvm alias default 12.x
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
Tejesh Palagiri
  • 729
  • 4
  • 9
40

This is what works for me.

nvm use default v16

This did not do anything for me

nvm alias default v16
okwyvic
  • 477
  • 5
  • 6
30

You can also like this:

$ nvm alias default lts/fermium
August Gong
  • 371
  • 4
  • 5
30

nvm alias default 16.10.0(your destination node version)

Huan
  • 301
  • 3
  • 3
26

For those testing this in VSCode terminal and still seeing the old version even after killing/restarting terminal -- VS code caches the old version somehow. Close/reopen your full VSCode window and you should see the correct version with node -v.

Kyle Chadha
  • 3,741
  • 2
  • 33
  • 42
21

Alert: This answer is for MacOS only

Let suppose you have 2 versions of nodeJS inside your nvm, namely v13.10.1 & v15.4.0

And, v15.4.0 is default

> nvm list
       v13.10.1
->      v15.4.0
         system
default -> 15.4.0 (-> v15.4.0)

And, you want to switch the default to v13.10.1

Follow these steps on your Mac terminal:

  1. Run the command:

    nvm alias default 13.10.1

This will make the default point to v13.10.1 as...

default -> 13.10.1 (-> v13.10.1)
  1. Open new instance of terminal. Now check the node version here as...

node -v

You will get...

v13.10.1
  1. nvm list will also show the new default version.

    nvm list

Just an info: The NodeJS versions taken as example above will have their different npm versions. You can cross-verify it in terminal by running npm -v

Rishabh Barman
  • 499
  • 5
  • 8
  • 1
    Excellent step by step, thank you. Works on ubuntu 20.04 – JasonCoder Sep 14 '22 at 18:33
  • @JasonCoder, oh you're welcome sir! Thanks for pointing out for Ubuntu :) In fact, my answer would work totally well for Linux and Windows systems too. On Windows, the user may do these steps via GitBash. – Rishabh Barman Oct 05 '22 at 19:03
18

In Nutshell steps to use NVM

For Mac

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash
nvm install 16
nvm use 16
nvm alias default 16
npm install npm --global # Upgrade npm to the latest version

For Linux

sudo apt install curl git
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs

For Windows

Git's installer for Windows from below link

https://git-scm.com/download/win

node-v16.XX.XX-x64.msi from below link

https://nodejs.org/dist/latest-v16.x/
dolar
  • 1,555
  • 1
  • 10
  • 9
16

I did something like that after running a nvm install --lts:

nvm alias default 'lts/*'
Maxime
  • 643
  • 10
  • 21
16

I was trying to change the default version from a VSCode terminal on a Mac. Didnt work. I had to run this from the default system terminal.

nvm alias default v16.16.0

Imtiaz Sakib
  • 1,231
  • 11
  • 8
14

I tried the most-upvoted answer and didn’t work for me. The problem was that I had another node installed by brew which NVM recognizes as system-node. NVM prioritizes system-node over default alias. All I had to was to uninstall the system-node (brew uninstall node).

Ingun전인건
  • 672
  • 7
  • 12
10

First check available versions

nvm list

Then set default version using

nvm alias default lts/**

enter image description here

Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38
10

nvm alias default v14.17.5

   mazin ~  nvm ls
           v10.15.1
    ->     v12.19.0
           v14.17.5
           v16.14.0
    default -> 12 (-> v12.19.0)
    node -> stable (-> v16.14.0) (default)
    stable -> 16.14 (-> v16.14.0) (default)
    iojs -> N/A (default)
    unstable -> N/A (default)
    lts/* -> lts/gallium (-> v16.14.0)
    lts/argon -> v4.9.1 (-> N/A)
    lts/boron -> v6.17.1 (-> N/A)
    lts/carbon -> v8.17.0 (-> N/A)
    lts/dubnium -> v10.24.1 (-> N/A)
    lts/erbium -> v12.22.10 (-> N/A)
    lts/fermium -> v14.19.0 (-> N/A)
    lts/gallium -> v16.14.0

     mazin ~  nvm use 14
    Now using node v14.17.5 (npm v8.7.0)

     mazin@zhihongtongxue  ~  nvm ls
           v10.15.1
           v12.19.0
    ->     v14.17.5
           v16.14.0
    default -> 12 (-> v12.19.0)
    node -> stable (-> v16.14.0) (default)
    stable -> 16.14 (-> v16.14.0) (default)
    iojs -> N/A (default)
    unstable -> N/A (default)
    lts/* -> lts/gallium (-> v16.14.0)
    lts/argon -> v4.9.1 (-> N/A)
    lts/boron -> v6.17.1 (-> N/A)
    lts/carbon -> v8.17.0 (-> N/A)
    lts/dubnium -> v10.24.1 (-> N/A)
    lts/erbium -> v12.22.10 (-> N/A)
    lts/fermium -> v14.19.0 (-> N/A)
    lts/gallium -> v16.14.0

     mazin ~  nvm alias default 14
    default -> 14 (-> v14.17.5)

     mazin ~  nvm ls
           v10.15.1
           v12.19.0
    ->     v14.17.5
           v16.14.0
    default -> 14 (-> v14.17.5)
    node -> stable (-> v16.14.0) (default)
    stable -> 16.14 (-> v16.14.0) (default)
    iojs -> N/A (default)
    unstable -> N/A (default)
    lts/* -> lts/gallium (-> v16.14.0)
    lts/argon -> v4.9.1 (-> N/A)
    lts/boron -> v6.17.1 (-> N/A)
    lts/carbon -> v8.17.0 (-> N/A)
    lts/dubnium -> v10.24.1 (-> N/A)
    lts/erbium -> v12.22.10 (-> N/A)
    lts/fermium -> v14.19.0 (-> N/A)
    lts/gallium -> v16.14.0
George Wayne
  • 160
  • 1
  • 5
7

nvm alias default 16 (where "16" is the version you want to use) but if you're install node from https://nodejs.org/en/download/ before I would suggest you remove it first. For m1 or m1 pro chips, I suggest you follow this solution: https://www.youtube.com/watch?v=fULL8QiPEU4

Harrison Cramer
  • 3,792
  • 9
  • 33
  • 61
5

The current answers did not solve the problem for me, because I had node installed in /usr/bin/node and /usr/local/bin/node - so the system always resolved these first, and ignored the nvm version.

I solved the issue by moving the existing versions to /usr/bin/node-system and /usr/local/bin/node-system

Then I had no node command anymore, until I used nvm use :(

I solved this issue by creating a symlink to the version that would be installed by nvm.

sudo mv /usr/local/bin/node /usr/local/bin/node-system    
sudo mv /usr/bin/node /usr/bin/node-system 
nvm use node
  Now using node v12.20.1 (npm v6.14.10)
which node
  /home/paul/.nvm/versions/node/v12.20.1/bin/node
sudo ln -s /home/paul/.nvm/versions/node/v12.20.1/bin/node /usr/bin/node

Then open a new shell

node -v
  v12.20.1
Paul Weber
  • 6,518
  • 3
  • 43
  • 52
5

Change the default version to use the latest LTS version nvm alias default lts/*

You manually upgrade the global version by doing nvm install lts/* --reinstall-packages-from=lts/* or a weekly cron job if you want to keep your version up to date

The --reinstall-packages-from=lts/* is there to reinstall the global packages you had everytime you change versions

Benos
  • 676
  • 7
  • 17
5

Since there are a lot of answers above that talk about the default alias, and someone still can't get the right version in new terminal, my answer is here.

while you add source $NVM_DIR/nvm.sh in your shell rc file(like ~/.bashrc), it will first check whether there is a nvm-version node path in the $PATH environment variable, like /usr/local/nvm/versions/node/v14.1.0/bin. If there is one, nvm will not use default alias.

So firstly you should check why there is node path in $PATH. If you could get the reason(like run nvm use 16 explicitly in another rc file or script file), just remove it.

If you can't get reason or just wanna keep it, then another solution is:

# that's your previous usage, keep it
source $NVM_DIR/nvm.sh

# FORCE to use default alias
nvm use default

# or if you prefer to forcedly use .nvmrc prior to default, then
test -f .nvmrc && nvm use || nvm use default
tianjianchn
  • 431
  • 5
  • 7
2

change the default node version with nvm alias default 10.15.3 *

(replace mine version with your default version number)

you can check your default lists with nvm list

Tong Yu
  • 167
  • 1
  • 5
2

#Worked for me 100% Follow this for default node version:

nvm install 12.13.1 then, nvm alias default 12.13.1

Rajbir
  • 31
  • 7
1

Make sure to have the correct version of node installed globally. Your company might be using a different version.

1

In my situation of Windows 11, nvm 1.1.9 and using gitbash

These work for me (have to run as administrator)

[lastest version]

nvm use latest

[specific version]

nvm use 18.10.0

These didn't work for me

nvm use 18 -> return node vv18.10.0 (64-bit) is not installed or cannot be found.

nvm use default 18 -> return Unrecognized version: "default"

nvm alias ... -> seems alias command is not supported in this nvm version

Hope it will help :)

Chester Chu
  • 395
  • 3
  • 11
1

FYI looks like tmux caches the old version also (like mentioned with VSCode above). restarting tmux then uses the new version for each window.

riordant
  • 98
  • 9
  • 1
    That was it! I had new version of node only in first pane, when I opened new one I got the old version. `tmux kill-server` helped. – user1068352 Jun 25 '23 at 17:29
-2

While NVM has its uses, I encourage you to consider an alternate option.

You can pin you project to a particular version of Node.js using the node package on Npm!

cd oldProject

npm i node@6.11.5

cd ../newProject

npm i node@9.0.0

Next time Npm runs node, it will use that version!

The node package accomplishes this by downloading the specified version of Node.js to node_modules/.bin/node. You you can run it directly, but it is easier to let Npm run it.

Any package.json#scripts will automatically use the specified version of node since node_modules/.bin is added to the path by Npm.

No more remembering which version of Node this package uses. No need to run anything new - just make sure npm i has been run.

{
  "scripts": {
    "node-version": "node --version"
  },
  "dependencies": {
    "node": "9.0.0"
  }
}

Note, you will need to npm install once before the correct node is used:

node --version
# v18.12.0
npm run node-version
# v18.12.0
npm install
npm run node-version
# v9.0.0
node --version
# v18.12.0
node_modules/.bin/node --version
# v9.0.0
Cameron Tacklind
  • 5,764
  • 1
  • 36
  • 45
-3

nvm alias default <node version>

this will make the <node version> default.

  • 4
    The only thing this "new" answer does is to repeat what half of the other answers are already saying, including the [accepted answer](https://stackoverflow.com/a/47787025/14267427). – Tyler2P Jun 30 '22 at 15:18
-3

nvm list <---- to get all available node vesions

nvm use v16 <----------- to switch your desired version

node -v <------------- to check the node version