Cannot upgrade Node.js using n - node.js

I'm trying to update Node.js on Ubuntu serever 14.04 using n.
n upgrades but the version is still the same:
root#0e2dbaa3db85:/home# node -v
v0.10.25
root#0e2dbaa3db85:/home# n 0.10.33
install : node-v0.10.33
mkdir : /usr/local/n/versions/node/0.10.33
fetch : https://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
installed : v0.10.33
root#0e2dbaa3db85:/home# node -v
v0.10.25
Do I have to tell n which version to use as default?
I've tried n latest, it installs 0.12.0 but node -v outputs 0.10.25 again.
What should I do?

On occasion the n package won't install the links for node, and the selection won't allow you to select any version installed by n.
When that happens, you need to install an "n" version of node so the selector will allow you to choose.
Here is what I had to do.
Use n to install a node version.
# n stable
install : node-v5.10.1
mkdir : /usr/local/n/versions/node/5.10.1
fetch : https://nodejs.org/dist/v5.10.1/node-v5.10.1-linux-x64.tar.gz
######################################################################## 100.0%
installed : v0.10.42
Select the node version from the install directory
In this case it is located at:
/usr/local/n/versions/node/5.10.1/bin/node
Replace existing node link with new node version
cd /bin
mv node node_old
ln -s /usr/local/n/versions/node/5.10.1/bin/node
At this point node should work, and n should allow you to select version.

Resolved by nvm.
I faced the same issue with you. I could not change node version with n because I installed nvm and used nvm to manage node versions before.
I resolved the issue by execute nvm command. For example: nvm install 11.8.0 then check node version node -v. Tada it works.

n 0.10.33 will install that version of node, but you still haven't selected it. After installing, simply execute n and pick the version you want to use.
n latest will install or activate the latest version of node. Run it twice to use node 0.12.0
Documentation.

I faced same issue, where I select a different version or even download a new version with n and it still shows the initial installation before I started using n. This worked for me:
Unlink
sudo unlink /usr/bin/node
Run n again to choose the node version.
After this two steps it worked

From what I can read from the n readme, you need to call n <version> to install, and then run n with no arguments, so a version picker will be shown:
Type n to prompt selection of an installed node. Use the up / down arrow to navigate, and press enter or the right arrow to select, or ^C to cancel:
(...)
Commands:
n <version> Install node <version>
However, if you run n latest, it will install or activate the latest version:
n latest Install or activate the latest node release

Try to set the simbolic link to node to the npm global folder.
sudo unlink /usr/bin/node
sudo ln -rs PATHTO/.npm-global/node/bin/nodee node
in my case, my path to npm-global dir was on my home. So the full path was /home/rafael/.npm-global/node/bin/node
After this, check if is allrigth:
node -v //return current node version
n stable //install the stable current version
node -v //will return the new version installed
n 8 //install the version 8 for test
node -v //will return the 8 version
Enjoy

Related

How to upgrade node to specific version in macOS Mojave, and update the active path for node?

I want to upgrade node to 12.10.0 and npm to 6.11.3, currently I am working on macOS Mojave version 10.14.5
I am using these commands to upgrade the node version to 12.10.0::
sudo npm cache clean -f (force) clear you npm cache
sudo npm install -g n install n (this might take a while)
sudo n 12.10.0 upgrade to the specific version
After running the last command it gives me an output like::
installing : node-v12.10.0
mkdir : /usr/local/n/versions/node/12.10.0
fetch : https://nodejs.org/dist/v12.10.0/node-v12.10.0-darwin-x64.tar.gz
installed : v12.10.0 to /usr/local/bin/node
active : v10.16.3 at /usr/local/opt/node#10/bin/node
When I am checking for node version node -v it still shows me old version 10.16.3
I have tried to add node path, but still, it gives me the same output.
I have used command sudo nano /etc/path and then added /usr/local/bin/node path to it.
Please suggest me how can I upgrade node to 12.10.0 and npm to 6.11.3 version?
Install nvm following below tutorial :
Install nvm with homebrew
As stated in the link above,
Start by :
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :
source ~/.bash_profile
echo $NVM_DIR
Then with the help nvm install any node version(example v12.14.1) you want :
nvm install v12.14.1
nvm use v12.14.1
to switch to 12.14.1 version.
Step 1: Clean npm cache
sudo npm cache clean -f
Step 2: Install node helper (n) globally using the following command.
sudo npm install -g n
Once node helper is installed. You can either get a specific version like I needed 16.14.1 then you can perform.
sudo n 16.14.1
OR You can get the latest stable version using
sudo n stable
Then you can confirm the version installed
node --version
install n (npm module) npm install -g n and run sudo n latest or sudo n <version>
An alternate way to upgrade w/o using brew -
Go to nodejs releases page. The table on this page list the various node release available for download.
Click on the downloads link for the version you need. This will take us to another page to download the node version depending on the OS you are using. For mac, we can download the .pkg format.
After the package is downloaded, we can run it by clicking the downloaded file and hitting 'Next' till we complete.

I cannot switch node.js version

I am trying to switch my node.js version.
What I did is:
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.10.0
But I check my current version after I did it by using
node -v
It always shows
v6.14.3
I am not sure if I do anything wrong. Any suggestion please?
As stated by Intervalia, try using using NVM (node version manager)
With nvm, you can very easily do things like:
nvm install 10.10.0 and it will download that version of node. And then do nvm use 10.10.0 and then doing node -v will return 10.10.0.
Here is what happens when I run nvm list

how to set specific version of node as default using n

I've installed node using the npm by below commands.
sudo npm cache clean -f
sudo npm install -g n
sudo n 8
sudo n 8 installed node 8 .
$ sudo n 8
install : node-v8.11.3
mkdir : /usr/local/n/versions/node/8.11.3
fetch : https://nodejs.org/dist/v8.11.3/node-v8.11.3-darwin-x64.tar.gz
######################################################################## 100.0%
installed : v6.13.1
but didn't set it as default
$ node -v
v6.13.1
How can I set node version 8 as default node version.
You still need to activate the installed version, installing doesn't automatically switch to that version. Type n after doing the install and select the version you want. From that point forward, it will be the node version your system uses. You may need to use sudo n if you run into permission issues.
Try to use NVM, you can have multiple versions of nodejs and it's pretty easy to manage.
https://github.com/creationix/nvm
For my case, i've deleted node package that was installed with system package manager (yum).
In my case, I couldn't change the node version because I installed node through brew, and was then trying to change the version through n (another node version manager, similar to nvm).
All I had to do was:
brew uninstall node
After this, I just had to run:
sudo n 18.14.1

Node doesn't appear to update using 'n'

I just noticed I'm on node version 4.0.0 and want to update to the latest version so I installed 'n' and ran sudo n stable in terminal
Machine-Name:directory name User$ sudo n stable
install : node-v9.8.0
mkdir : /usr/local/n/versions/node/9.8.0
fetch : https://nodejs.org/dist/v9.8.0/node-v9.8.0-darwin-x64.tar.gz
################################################################## 100.0% installed : v4.0.0
Machine-Name:directory name User$ node -v
v4.0.0
The latest version downloads, but the installed version remains at v4.0.0. Is there something else I need to do in order for node to install/use the downloaded version?
The issue will be that you have two versions of node now. n installs to /usr/local/ by default and presumably you have another version of node earlier in your PATH.
If you are happy with the n managed version then a simple approach is to uninstall the other one.
Alternatively, you could modify PATH to prioritize /usr/local/ over the other location. [from comments]
(If your OS supports it, which -a node shows the locations of all the versions in your PATH.)

How to check and change the Nodejs version on Ubuntu?

I am using Ubuntu Linux.
How can I check current nodejs version? I guess, I have 6 version, but I am not sure.
And is there way to change it, because I need 4 version. Can some one give step by step commands?
Open up the terminal and type node -v
To change your node version, I'd recommend installing nvm. Once installed, to switch versions it's as simple as
nvm use <version>
You can check your current NodeJS version by using command node -v.
And changing your version can be done by using node version manager.
The easiest way to do that is by running this $ npm install -g n now you can change your current NodeJS version using n (version)
e.g. n 4.0.0.
node -v
npm install -g n
n 4.0.0
You can check your version by using this code (node -v) in linux terminal and If you want to upgrade it to stable version you can use following codes one by one.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.
To change your node version, I'd recommend installing nvm. Once installed, switch versions follow the instruction below;
nvm use <any specified version you prefer "example v16.0.0">
Example:
nvm alias default 16
This will enforce as the current default version.

Resources