NVM ls command not picking existing Node version - node.js

I have already installed Node specific version in my system.
Now i have installed NVM using below command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
if I run nvm in terminal , its showing all NVM options user can try. ( NVM installation is Successful)
My doubt is it not taking up already installed node version on nvm ls
PFA
nvm ls
> -> system
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)
Please let me know how NVM can detect already installed node version.
If i install other node version with NVM , i may loose track of already installed node version as its not coming up in nvm ls

When I installed nvm recently I had to also do this step: nvm install node to install the latest version. Then you can check the following: node -v
If you do nvm ls remote it will display all available versions, then you can install any of them and view which ones you picked using nvm ls.
I set my node version default like this: nvm alias default <version>
I just ran into this issue as well using nvm. I did have to delete the package-lock.json file in the project directory and rebuild. But after doing so it seems to not have any trouble going between the node versions.
I just noticed you asked the question 4 months ago! I hope you were able to resolve the issue!

Related

Node version not updating after "nvm use" on mac

I am trying to update my local node version from 8.9.0 to 8.10.0 using nvm. But it's not getting reflected. Here's what I tried:
node -v
-> v8.9.0
nvm use 8.10.0
-> Now using node v8.10.0 (npm v5.5.1)
node -v
-> v8.9.0
I am unable to get why it won't change. Please let me know what have I done wrong.
Adding few notes about my experience on debugging this problem.
First, I started out with the command provided by Jonathan which -a node and got the same output as op:
/usr/local/bin/node
/Users/<my-user>/.nvm/versions/node/v8.10.0/bin/node
Moving on to the next comment by Jonathan: Have you installed Node via Homebrew as well?, I tried uninstalling node by brew uninstall node and got and error that said it could not uninstall node as there was another program dependent on it. yarn.
And then realised that brew had installed its own version of node because I installed yarn through brew, which was overwriting the node version that I wanted to use through nvm.
Uninstalling brew's version of yarn+node fixed my problem.
I still needed yarn, and now I have to install yarn globally for each node version managed by nvm.
Inconvenient, I agree. But so is maintaining twenty thousand versions of node for each project so not very different in my opinion.
All of this was done on M1 MacOS and your output might vary based on your system.
Please ensure that when you input arch on command prompt, then output is i386.
This is achieved using Rosetta.
Following sequence of commands on terminal worked: -
nvm install 8.10.0
nvm install --lts
nvm ls
brew upgrade
arch -arm64 brew install n
n
Now select node version 8.10.0 using up or down arrow keys in keyboard and then quit from command prompt using command+q
Please do not try brew uninstall --ignore-dependencies node
Just check you environment variables first. It might be mapping to node#8.9.0.
You need to remove the environment variable first.
If you are also using volta. Volta may take precedence.
Use which -a node to verify.
If that is the case, use volta pin node#version to switch.
First check your nvm version installed on your local system. go to command prompt and type "nvm list" If you don't see the versions 8.10.0 in the list then install using command : "nvm install 8.10.0" and then try "nvm use 8.10.0".
For reference : http://www.tutorial-points.com/2018/11/nvm-installation-on-windows.html

Can't update node globally with nvm?

I want to upgrade node to v8.3 globally. I'm working on the latest OSX and using v0.33.0 of nvm.
I can upgrade successfully in one bash shell:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ nvm install 8.3 --reinstall-packages-from=8.1
v8.3.0 is already installed.
Now using node v8.3.0 (npm v5.3.0)
Reinstalling global packages from v8.1.4...
Linking global packages from v8.1.4...
$ node -v
But then if I open a new shell, it's still pointing at the old version:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ node -v
v8.1.0
What am I doing wrong? I can't see anything in my bash profile pointing to the older version.
You need to also set your default node version, like this:
nvm alias default 8.3.0
This should set your version moving forward. Credit:
https://eric.blog/2016/08/23/set-default-node-version-with-nvm/

nvm: N/A: version "N/A -> N/A" is not yet installed

I have nvm setup to use the latest long term support version in ~/.nvm/alias/default, by setting it to lts/*.
When I try and have my shell initialize my nvm version (zsh), I get the following error:
N/A: version "N/A -> N/A" is not yet installed.
Why is this happening?
Error: N/A: version "N/A -> N/A" is not yet installed
I got this error after doing nvm use (switching to older Node version 8.11.1, shown in .nvmrc file), nvm uninstall (newer Node version 9.0.0), then a git push.
nvm ls shows my "default" Node version was pointing to the uninstalled one: default -> 9.0.0 (-> N/A). This caused the error.
To fix: nvm alias default node points "default" to the latest installed Node version (8.11.1).
Now nvm ls shows default -> node (-> v8.11.1).
Turns out this error is telling me that I don't have it installed (ie the latest long term support version). To fix it, I had to run:
$ nvm install 'lts/*'
and it worked after that! Snagged from here
Your "default" Node version is not reachable (many reasons)
Many answers but there isn't a straightforward solution, let's try with:
nvm install 'lts/*'
nvm alias default node
the first command ensure you have latest LTS version installed and then set the default.
I faced the same issue when i used nvm to install node 12 and node 10. To fix this i used the command:
nvm alias default node
Prevent nvm from trying to use when first loading
You may not need (or want) the latest version of node installed, and yet wish to have the nvm command available, so in your .bashrc (or equivalent) include the --no-use flag when loading nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
Thanks to Ioannis Poulakas
I fixed it by running nvm use v12.21.0

How can I use nvm to manage multiple locally installed node.js?

I already have multiple node.js versions installed locally in my x-Linux box,
0.10.40, 0.12.7 and 4.0
My default profile is pointing to node.js 0.12.7
Currently, I set my PATH to point to different versions of node when I start a new terminal.
I would like to use node version manager to use and manage different version of node that is already installed in my environment .
How should I do it without reinstalling node again?
Answering Original Post
For the small amount of data that you'd save by doing the following, it's almost not worth it. That being said...
Find where current versions are stored in nvm:
> nvm which
# mac
/Users/[username]/.nvm/versions/node/[version]/bin/node
# linux
/home/[username]/.nvm/versions/node/[version]/bin/node
Find all your non-nvm installed versions of node:
> which -a node
(..pending how you are running each of your terminals for each version of node installed will tell how effective this command will be).
Then symbolic link each of them to a folder matching the version.
> ln -s /path/to/node/version ~/.nvm/versions/node/[version]
# `$HOME` or `~/` or `/Home/username/` ... you know which works.
Node and Version Swapping Made Simple
nvm-controlled versions of node installed
> nvm ls
v0.10.33
v0.10.36
v0.10.40
v4.0.0
v4.2.2
v5.0.0
-> v5.1.1
system
default -> v5.1.1
system -> v5.1.1
node -> stable (-> v5.1.1) (default)
stable -> 5.1 (-> v5.1.1) (default)
iojs -> N/A (default)
Install version x, x.y, or x.y.z: nvm install x.y.z.
ie:
> nvm install 4.2.2
# If you want all modules from another version too:
> nvm install 4.2.2 --reinstall-packages-from=0.10.40
Set the default version used:
> nvm use 5.1.1
# But if only a local node command required, use:
# nvm exec [version] [command]
> nvm exec 0.10.33 node server.js
.nvmrc file in project root to define which local version of node to use.
#.nvmrc file contents:
5.1.1
You can't using installed nodejs version with nvm,
Because nvm use own directory for managing versions
You just need reinstall node versions
nvm install 0.12.7
And then
nvm use 0.12.7

How to change to an older version of Node.js

I am running Node.js version v0.5.9-pre on Ubuntu 10.10.
I would like to be using version v0.5.0-pre.
How do I roll back to the older version of node?
*NIX (Linux, OS X, ...)
Use n, an extremely simple Node version manager that can be installed via npm.
Say you want Node.js v0.10.x to build Atom.
npm install -g n # Install n globally
n 0.10.33 # Install and use v0.10.33
Usage:
n # Output versions installed
n latest # Install or activate the latest node release
n stable # Install or activate the latest stable node release
n <version> # Install node <version>
n use <version> [args ...] # Execute node <version> with [args ...]
n bin <version> # Output bin path for <version>
n rm <version ...> # Remove the given version(s)
n --latest # Output the latest node version available
n --stable # Output the latest stable node version available
n ls # Output the versions of node available
Windows
Use nvm-windows, it's like nvm but for Windows. Download and run the installer, then:
nvm install v0.10.33 # Install v0.10.33
nvm use v0.10.33 # Use v0.10.33
Usage:
nvm install [version] # Download and install [version]
nvm uninstall [version] # Uninstall [version]
nvm use [version] # Switch to use [version]
nvm list # List installed versions
One way is to use NVM, the Node Version Manager.
Use following command to get nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
You can find it at https://github.com/creationix/nvm
It allows you to easily install and manage multiple versions of node. Here's a snippet from the help:
Usage:
nvm install <version> Download and install a <version>
nvm use <version> Modify PATH to use <version>
nvm ls List versions (installed versions are blue)
Update: Updated the answer because previous one was not relevant.
Follow below steps to update your node version.
1. Install nvm For this run below command in your terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Note: If above command did not work for you, you can choose another option to install it. I have added an answer for this here
2. Install specific node version using nvm
For this run
Replace 12.14.1 with your node version
nvm install 12.14.1
Note: If you are getting error of NVM not recognised then run below command and then run above again
source ~/.nvm/nvm.sh
3. Make the installed version default
Note: Replace 12.14.1 with your installed version.
nvm alias default 12.14.1
and
nvm use 12.14.1
4. Check node version
node -v
And that's it.
Extra
To check list of installed node versions -- run below command
nvm ls
Why use any extension when you can do this without extension :)
Install specific version of node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Specific version : sudo n 4.4.4 instead of sudo n stable
With package.json - The Maintainable and Portable Way 🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉
Lets each project specify its own version
You can add node as a dependency in package.json and control which version is used for a particular project. Upon executing a package.json "script", npm (and yarn) will use that version to run the script instead of the globally installed Node.js.
The node package accomplishes this by downloading a node binary for your local system and puts it into the node_modules/.bin directory.
You can also do this with the npm (or yarn) packages but you'll need to set your PATH up specifically or use something like npx that handles it for you.
Ubuntu - The Official Way (manually) 😵
If you're on node 12 and want to downgrade to node 10, just remove node and follow the instructions for the desired version:
# Remove the version that is currently installed
sudo apt remove -y nodejs
# Setup sources for the version you want
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# (Re-)Install Node
sudo apt-get install -y nodejs
Windows - The Official Way (manually) 😵
I found myself wanting to downgrade to LTS on Windows from the bleeding edge. If you're not using a package manager like Chocolatey or a node version manager like nvm or n, just download the .msi for the version you want and install it. You might want to remove the currently installed version via "Add or remove programs" tool in Windows.
Windows Package Manager - winget 🎉🎉
The Open Source Windows Package Manager Way
winget install -e --id OpenJS.Nodejs -v 14.9.0
Chocolatey - The Independent Package Manager Way 🎉
Chocolatey is good for keeping installations up to date easily and it is a common way to install Node.js on Windows. I had to remove the bleeding edge version before installing the LTS version:
choco uninstall nodejs
choco install nodejs-lts
Node Version Manager - The "Screw it, I'll do it myself!" Way 😢😢😢😭😭😭😭😭
While not very portable or easily maintainable, some developers like manually switching which global version of node is active at any given point in time and think the official ways of doing this are too slow. There are two popular Npm packages that provide helpful CLI interfaces for selecting (and automatically installing) whichever version you want for your system: nvm and n. Using either is beyond the scope of this answer.
I highly recommend staying away from this option. Even though it's popular, it's an anti-pattern that is sure to cause headaches in the future. Sure, .nvmrc exists, but this is reinventing something that's already a part of Npm. Just npm i node the version you want.
Windows
Downgrade Node with Chocolately
Install Chocolatey. Then run:
choco install nodejs.install -version 6.3.0
Chocolatey has lots of Node versions available.
Downgrade NPM
npm install -g npm#3.10.3
the easiest way i have found is to just use the nodejs.org site:
go to https://nodejs.org/en/download/releases/
find version you want and click download
on mac click the .pkg executable and follow the installation instructions (not sure what the correct executable is for windows)
be happy now that you are on the version of node you wanted
nvmw is no longer maintained, but I found another source that seems to be up to date (as of 1/4/17).
nvm-windows
It works. Allowed me to downgrade to 6.3.1
You need to install NVM for this.
For Mac
Edit .bash_profile using the below command.
nano .bash_profile
And add the following lines to .bash_profile
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
Save it. Exit the terminal and check the magic.
Then install the required version using the below command.
nvm install v14.18.0
If you want to check the installed node versions on your system. Use the below command.
nvm ls
If you want to use the specific version from the installed node versions. Use below command
nvm use 12.14.4
Another good library for managing multiple versions of Node is N: https://github.com/visionmedia/n
On windows 7 I used the general 'Uninstall Node.js' (just started typing in the search bottom left ,main menu field) followed by clicking the link to the older version which complies with the project, for instance:
Windows 64-bit Installer: https://nodejs.org/dist/v4.4.6/node-v4.4.6-x64.msi
I had node version 6.4.0 .
As i am need of the older version 6.3.0 , i just installed the 6.3.0 version again in my system. node version downgraded automatically.
So, to downgrade the node version ,
Just install the older version of node js . It will get downgraded automatically from the higher version.
I tried in osx . It works like a charm .
Now the v0.5.0-pre has reached end of life. We can use npx to use any stable older version of node. E.g. the earliest stable version is 4.9.0.
npx -p node#4.9.0 -- node -v
run this:
rm -rf node_modules && npm cache clear && npm install
Node will install from whatever is cached. So if you clear everything out first, then NPM use 0.10.xx, it will revert properly.
Easiest way i found -
Uninstall current version
Download the appropriate .msi installer (x64 or x86) for the desired version from https://nodejs.org/download/release/
Use following commnad with your version number
nvm install v8.9
nvm alias default v8.9
nvm use v8.9
For some reason Brew installs node 5 into a separate directory called node5.
The steps I took to get back to version 5 were: (You will need to look up standard brew installation/uninstallation, but otherwise this process is more straightforward than it looks.)
Install node5 using Brew standard installation, BUT don't brew link, yet.
Uninstall all other versions of node using brew unlink node and brew uninstall node. You might need to use --force to remove one of the versions.
Find the cellar folder on your computer
Delete the node folder in the cellar.
Rename the node5 folder to node.
Then, brew link node
You should be all set with node 5.
If you are like, you already install node version you want but can't seem to switch to it, try this:
nvm use --delete-prefix <version>. npm shows the lates version installed but can't switch to it. If so, this is the output you will see:
You need to run "nvm install v16.2.0
Then run:nvm install <type the version you wish to use here>Your output should look like this:
Downloading and installing node v16.2.0... Downloading https://nodejs.org/dist/v16.2.0/node-v16.2.0-linux-x64.tar.xz... ####################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v16.2.0 (npm v7.13.0) Creating default alias: default -> v16.2.0
You are done! You can see the latest version by running:
node -v
if you want to go to the LTS version of node which is the stable one from the latest/current version simply run this in your directory.
npm i node
this will install the LTS version of node in your directory.
I faced a lot of issue with this and the only solution that worked for me is :
source ~/.nvm/nvm.sh
nvm isntall node_version_you_want
nvm use node_version_you_want
nvm install 0.5.0 #install previous version of choice
nvm alias default 0.5.0 #set it to default
nvm use default #use the new default as active version globally.
Without the last, the active version doesn't change to the new default. So, when you open a new terminal or restart server, the old default version remains active.
follow the steps if u already install curl its work for me
sudo snap remove curl
sudo apt install curl
nvm install 12.2.0
As i can see this was asked a long time ago, but maybe it can be helpful for someone else.
I can recommend this utility (NVS - Node Version Switcher) to someone who is searching for a way to switching between different versions of NodeJS:
https://github.com/jasongin/nvs
The Easiest way I find to install node.js with a specific version:
First uninstall your node.js
Go to, https://nodejs.org/en/download/releases/ and find your desired version.
Select your version and click on the download button.
Download .msi file

Resources