NVM on WSL2: cannot install Node, version not found - node.js

I installed WSL from the Microsoft Store onto Windows 10. I was able to succesfully install NVM onto this using the curl command as documented on https://github.com/nvm-sh/nvm
NVM installs, I can run commands and check the version.
However when I try to install node, either a specific version like nvm install 12.18.1 or nvm install or nvm install --lts I get a message that the version is not found
me:~$ nvm install 12.18.1
Version '12.18.1' not found - try `nvm ls-remote` to browse available versions.
or
me:~$ nvm install --lts
Installing latest LTS version.
Version '' (with LTS filter) not found - try `nvm ls-remote --lts` to browse available versions.
If I try to run nvm ls-remote, after several seconds I get N/A
I have installed this before on MacOS and on a different non-work Windows 10 box and have not seen this behavior before. It's like it is not hitting the nodejs server.
Thoughts?

I had experienced the same issue on a work laptop running WSL2. It was caused by a proxy/firewall solution (ZScaler) installed on the PC which was blocking connections to nodejs.org. To test is this is the issue you can run the command below to see if it runs successfully
curl -I --compressed -v https://nodejs.org/dist/
The solution for me was to run a VPN on my PC which would bypass that restrictions of the corporate proxy and allow me to download the node versions required. Alternatively you can work with your IT department to have nodejs.org unblocked.

Related

I just installed Nodejs 14.4 from the site, but when I check the version in Command Prompt it shows version 8.10

title says it all. I have been using nodejs with npm for while now and it has been working fine, but I went to check the version and noticed it was an older one. Nodejs - version 8.10.0 and npm - version 3.5.2. I know there are more recent versions of each and like I said I went to download the new version of Nodejs and I got it. I have the path set up to its location in my Environment Variable. I'm not sure what I'm missing. Would love any help.
Edit: Forgot to mention on my original post that I am on Windows.
Edit2: So I was looking at it more and I am using the Ubuntu Bash Shell on muy windows computer. Whenever I check the version in the normal Windows Command Prompt it displays the right version, but when I check it in the Bash shell it is wrong. Any ideas why this happens?
The Node Version Manager. You can find it at https://github.com/coreybutler/nvm-windows
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)
install and Usage:
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
and then
nvm use 6.14.4
So, I was able to solve my own issue
These two links were very important for solving my issue:
E: Unable to locate package npm
https://learn.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2
So basically after uninstalling nodejs I went and tried uninstalling and reinstalling my Ubuntu Bash shell. Once I had the Bash shell set up again I tried running the commands listed in the stackoverflow post I have listed above. (note: When you run the curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - line you need to adjust the "setup" version to 14.x) When I ran all the commands I was able to get my npm version up-to-date, but my nodejs was still being stuck at version 10.x. I tried running the install again on nodejs and thats when I noticed an error reading gpg: can't connect to the agent: IPC connect call failed I did some research on this error and foudn out my WSL1 would not allow it to update to the most recent version. Thats how I found my way to the Microsoft page that led to me needing to update my version of Windows to 1909 and then installing WSL2 through Power Shell. Everything is now up-to-date and working!
You could Uninstall both versions and reinstall the newer version. That should do it
Or better still download the NVM and follow the instructions from here
https://blog.logrocket.com/switching-between-node-versions-during-development/

I want to install nodejs with latest version

Currently, I have node version 10.10.0. I want to install it with the latest version. On my ubuntu 18.4 LTS bionic.
I tried using
url -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install nodejs
node -v
but it still shows the older version
I have also tried
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 12.12.0
these steps show 12.12.0 version on node -v command, but when I open a new terminal or virtual environment it again shows the older version which is 10.10.0. Please provide a solution.
You need to use a node version manager and set the default node version. Use below command to set the default version.
nvm alias default <version>
e.g nvm alias default 12.12.0
You can use nvm use 12 to make the terminal recognize which version you want to use
I just did pip3 install npm.
Worked for me.
I installed a brand new ubuntu 16.04 64-bit on my VirtualBox. Here is what I did to install latest version nodejs:
go to https://nodejs.org/, click on 12.16.1 LTS, which is the latest version I could get. download will be initiated in a few seconds
create a folder for nodejs(if not exist):
sudo mkdir -p /usr/local/lib/nodejs
uzip to the folder just created:
sudo tar -xJvf node-v12.16.1-linux-x64.tar.xz -C /usr/local/lib/nodejs
set the environment variable ~/.profile, add below to the end of the file(make sure you don't have duplicate in this file)
# Nodejs
VERSION=v10.15.0
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
refresh the profile
. ~/.profile
Congratulations! Now if you issue node -v, you should get v12.16.1.
This may not be the optimal way to update the nodejs if you currently have one previous version installed, but it can let you choose which one to keep (by modifying the PATH, another file you may want to touch is /etc/profile).
I also suggest you uninstall current nodejs (e.g. sudo apt-get purge node) before proceed to install the lastest one.
Reference:
Installation - nodejs help page on github

How to downgrade Node version

I want to downgrade my Node version from the latest to v6.10.3.
But nothing worked so far. Tried NVM and it gives an error as well by saying make command is not found. How can I downgrade Node?
Warning:
This answer does not support Windows OS
You can use n for node's version management. There is a simple intro for n.
$ npm install -g n
$ n 6.10.3
this is very easy to use.
then you can show your node version:
$ node -v
v6.10.3
For windows nvm is a well-received tool.
For windows:
Steps
Go to Control panel> program and features>Node.js then uninstall
Go to website: https://nodejs.org/en/ and download the version and install.
Determining your Node version
node -v // or node --version
npm -v // npm version or long npm --version
Ensure that you have n installed
sudo npm install -g n // -g for global installation
Upgrading to the latest stable version
sudo n stable
Changing to a specific version
sudo n 10.16.0
Answer inspired by this article.
In Mac there is a fast method with brew:
brew search node
You see some version, for example: node#10 node#12 ... Then
brew unlink node
And now select a before version for example node#12
brew link --overwrite --force node#12
Ready, you have downgraded you node version.
This may be due to version incompatibility between your code and the version you have installed.
In my case I was using v8.12.0 for development (locally) and installed latest version v13.7.0 on the server.
So using nvm I switched the node version to v8.12.0 with the below command:
> nvm install 8.12.0 // to install the version I wanted
> nvm use 8.12.0 // use the installed version
NOTE: You need to install nvm on your system to use nvm.
You should try this solution before trying solutions like installing build-essentials or uninstalling the current node version because you could switch between versions easily than reverting all the installations/uninstallations that you've done.
For windows 10,
Uninstalling the node from the "Add or remove programs"
Installing the required version from https://nodejs.org/en/
worked for me.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
sudo npm install -g n
sudo n 10.15
npm install
npm audit fix
npm start
If you're on Windows I suggest manually uninstalling node and installing chocolatey to handle your node installation. choco is a great CLI for provisioning a ton of popular software.
Then you can just do,
choco install nodejs --version $VersionNumber
and if you already have it installed via chocolatey you can do,
choco uninstall nodejs
choco install nodejs --version $VersionNumber
For example,
choco uninstall nodejs
choco install nodejs --version 12.9.1
If you are on macOS and are not using NVM, the simplest way is to run the installer that comes from node.js web site. It it clever enough to manage substitution of your current installation with the new one, even if it is an older one. At least this worked for me.
Try using the following commands
//For make issues
sudo apt-get install build-essential
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
//To uninstall a node version
nvm uninstall <current version>
nvm install 6.10.3
nvm use 6.10.3
//check with
node -v
Steps to downgrade to node8
brew install node#8
brew link node#8 --force
if warning remove the folder and files as indicated in the warning then again the command :
brew link node#8 --force
For windows users, you guys can downgrade using following commands.
npm uninstall -g node
npm install -g node#version
#version is your specified version, example : 12.22.3(little old)
Can find node releases here https://nodejs.org/en/download/releases/
I have used brew in mac to downgrade the node
follow the steps you will have the result:
brew search node (here you can see the version eg: node#10, node#12, node#14)
brew unlink node
brew install < node version > (eg: node#12)
brew link --overwrite node#12
If you are using nvm, following are the ways -
1. nvm install node_version
2. nvm use --delete-prefix node_version
For more insights, see this image -
Ubuntu:
nvm list
nvm use <version>
nvm list // Shows all the versions on your machine. Of course have your version installed.
nvm use // Use this version
it seems to be a compatibility issue, run
sudo n 14
then npm install or yarn install again. It will work
In case of windows, one of the options you have is to uninstall current version of Node. Then, go to the node website and download the desired version and install this last one instead.
I had to downgrade node to v10.16.0
sudo n 10.16.0
nvm use v10.16.0
this solved the problem for me
WINDOWS: Best way that you can do it and to not lose time.
Go to control panel
Uninstall Program
Uninstall node
Then go and find the version that you want to install, install it from the beginning.
Link with node versions: https://nodejs.org/uk/blog/release/
Here is a simple solution
Go to this link and download & install the suitable nvm setup on your computer
https://github.com/coreybutler/nvm-windows
Type nvm list to get list of installed node versions
Type nvm install <node-version>
Type nvm use <version>
here we go you got node version you want.
Browse here to find node versions => https://nodejs.org/en/download/releases/
The Node.js team suggests to use the following Node.js version managers to switch between different versions of Node:
OSX or Linux:
nvm
n
Windows:
nodist
nvm-windows
I personally made good experiences using "nvm-windows" on Windows 11.
I would recommend using NVS (Node Version Switcher).
You can see the source here and all you need is a package manager. Like Chocolatey or Homebrew.
Install it
choco install nvs
Add a version:
nvs add v16
Switch to any version you installed
nvs use v16
At the end if you "run node -v" you'll get the current you've switched.

Can somebody please tell me if I am using the wrong node js version?

I have been trying to update nodejs for a long time now. When I run node -v, it tells me I am using: v0.10.40. But when I look at nodejs.org it says the v7.4.0?
I have cleaned the npm cache and done a reinstall with sudo n stable but still v0.10.40, and the last time that I updated npm it prompted me that my node version is too old and outdated.
What am I doing wrong. And can somebody tell me if v0.10.40 is the current or an outdated version?
You likely have two versions of node installed and in your path. If you are on OSX or linux, run which node (if on Windows, you may npm i -g #raider/which, and then run which node). This should give you the location of the old version of node.
Then run mv path/to/old/node path/to/old/node.bak, replacing with the actual path, and rerun node --version to see if it picks up the right version now.
UPDATE: If you are on Ubuntu or another Debian based Linux, you should install the latest with the following commands:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
UPDATE: If you are using nvm, run nvm install node followed by nvm use node in a new terminal to get the latest that nvm supports.

How to properly upgrade node using nvm

Is it possible to upgrade node right in place, instead of manually installing the latest stable version?
I have installed node.js version 5.0 with nvm, but now I want to update it to 5.4. I'm trying to avoid having to manually reinstall all of my global packages (e.g. by running npm install -g grunt-cli bower yo yoman-angular-generator blabla blablablabla...).
This may work:
nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION
For example:
nvm install 6.7 --reinstall-packages-from=6.4
then, if you want, you can delete your previous version with:
nvm uninstall OLD_VERSION
Where, in your case,
NEW_VERSION = 5.4
OLD_VERSION = 5.0
Alternatively, try:
nvm install stable --reinstall-packages-from=current
You can more simply run one of the following commands:
Latest version:
nvm install node --reinstall-packages-from=node
Stable (LTS) version: (if currently in use)
nvm install "lts/*" --reinstall-packages-from="$(nvm current)"
This will install the appropriate version and reinstall all packages from the currently used node version.
This saves you from manually handling the specific versions.
Kudos to #m4js7er for commenting about the LTS version.
⚡ TWO Simple Solutions:
To install the latest version of node and reinstall the old version packages just run the following command.
nvm install node --reinstall-packages-from=node
To install the latest lts (long term support) version of node and reinstall the old version packages just run the following command.
nvm install --lts /* --reinstall-packages-from=node
Here's a GIF animation to support this answer:
if you have 4.2 and want to install 5.0.0 then
nvm install v5.0.0 --reinstall-packages-from=4.2
the answer of gabrielperales is right except that he missed the "=" sign at the end. if you don't put the "=" sign then new node version will be installed but the packages won't be installed.
source: sitepoint
Here are the steps that worked for me for Ubuntu OS and using nvm
Go to nodejs website and get the last LTS version (for example the version will be: x.y.z)
nvm install x.y.z
# In my case current version is: 14.15.4 (and had 14.15.3)
After that, execute nvm list and you will get list of node versions installed by nvm.
Now you need to switch to the default last installed one by executing:
nvm alias default x.y.z
List again or run nvm --version to check:
Update: sometimes even if i go over the steps above it doesn't work, so what i did was removing the symbolic links in /usr/local/bin
cd /usr/local/bin
sudo rm node npm npx
And relink:
sudo ln -s $(which node) /usr/local/bin/nodesudo && ln -s $(which npm) /usr/local/bin/npmsudo && ln -s $(which npx) /usr/local/bin/npx
Node.JS to install a new version.
Step 1 : NVM Install
npm i -g nvm
Step 2 : NODE Newest version install
nvm install *.*.*(NodeVersion)
Step 3 : Selected Node Version
nvm use *.*.*(NodeVersion)
Finish
Bash alias for updating current active version:
alias nodeupdate='nvm install $(nvm current | sed -rn "s/v([[:digit:]]+).*/\1/p") --reinstall-packages-from=$(nvm current)'
The part sed -rn "s/v([[:digit:]]+).*/\1/p" transforms output from nvm current so that only a major version of node is returned, i.e.: v13.5.0 -> 13.
For Windows 11 this worked for me on cmd, used with admin rights:
Prerequisite, in case you just installed NVM, is to open a new cmd window after nvm installation.
See installation instructions here: https://github.com/coreybutler/nvm-windows
Get installed versions, using
nvm list
Get current version
nvm current
Install latest version
nvm install latest
Check installed versions to see for newer version, again using
nvm list
Set current version to the latest (cmd with admin rights), you just installed in the previous step
nvm use PUT_VERSION_NUMBER_TO_BE_USED
You can check again if the change was successful using
nvm list
Remove old version, if no longer needed
nvm remove PUT_VERSION_NUMBER_TO_BE_REMOVED
If you want to use the LTS version, install using
nvm install lts
Here's the steps to upgrade NodeJs version:
Run nvm install node (will install latest version). Alternatively, you
can specify a specific version by running nvm install <node_version>.
Run nvm use <node_version> to use it.
If you want to make it the default version on your machine, run nvm alias default <node_version>.
Additional notes:
To find out what node versions you have on your machine and which one is set as your default one, use nvm list command.

Resources