Update node to v12 on ubuntu
Asked Answered
D

3

13

I want to update my node to version greater than v10 but i still get v9.11.2. I tried this commands

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

and i am still on v9.11.2 i also remove and reinstall but no change. With n :n latest the answer it's also v9.11.2 with sudo apt-get install --only-upgrade nodejs the response is: your version is up to date

I really need v10 and greater for my loopback project

Danella answered 14/3, 2020 at 5:3 Comment(0)
D
33

First remove nodejs using,

sudo apt-get purge --auto-remove nodejs

Then after, if curl is not installed then run the below command

sudo apt-get install curl

Then after run the below 2 commands,

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

sudo apt-get install -y nodejs

Disruptive answered 14/3, 2020 at 5:16 Comment(4)
I still have v9.11.2 after all thisDanella
@gildaskevin this command worked for me.. sudo apt-get install -y nodejsSilvanus
I followed the steps, but I still have version 10. Trying to get version 12 .Incongruity
Same issue for me. It still install Node 10.Pronation
E
3

You can install the latest version from non Official Ubuntu repos.

First you can use a PPA (personal package archive) maintained by NodeSource.

curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh

Change the permission to 755 or 764 and run the file

sudo bash nodesource_setup.sh

The PPA will be added to your configuration and now you can install the Node.js package...

sudo apt install nodejs
node -v

v16.10.0

Edibles answered 27/9, 2021 at 0:52 Comment(1)
No need to chmod the downloaded file - simply invoking using bash will suffice. Also, as of 2024, setup_20.x is the LTS version of node.js. (reader from the future - node will let you know what the current LTS version is)Deception
D
0

Node Version Manager

I have been through all of the ways to do this, and as of 2022, I can tell you that the best way is to use NVM. You can get the free opensource version managment tool freely by visiting the repository at the link above (click on the title), or you can simply use the following command, which auto-updates your $HOME/.bashrc configuration. Because your .bashrc is updated, there is no need to do anything, beyond the curl command below, to install NVM.




NVM via Curl:

  • curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash


Alternatively, if you prefer wget, use the following...


NVM via Wget

  • wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash



At this point you can preform the following commands.

If you don't have NPM you can start with this command

~$> nvm install-latest-npm

The above will upgrade to the latest NPM version for the current node version.


If you have NPM, or already installed NPM as shown above, get the latest node version with the command below.

~/$> nvm install node

the above installs the newest version of node.

If you want the long term support version instead, preform this command

~/$> install --lts

you can switch between the two by using the following:

~/$> use node   -or-   ~/$> nvm use --lts

you can also use...

~/$> install 10.1.2

To install a different version, just replace 10.1.2 with the version you want



There is one hiccup that occurs when choosing to use NVM (Node Ver Manager) as your method for installing Node.js, however; it is easily dealt with.


On an Important Side Note:
Many developers struggle with the "hiccup" that I am referencing. Its not a difficult thing to fix, but it is important to know how to fix it so your Linux Operating System & Commands work as you intend for them to (and as you desire for them to).


THE NVM HICCUP


Step #1

When NVM updates & installs Node.js & NPM, the versions that you install, each get placed into the directory @ "$HOME/.nvm/versions/node".

The problem with this is even though you use NVM to upgrade Node.js, when you use the command node -v the console will print the old version, because your binaries haven't been updated with a symbolic link to the new node version.


SOLUTION, Adding upgraded Symbolic Link for Node.js


I suggest that you look at that directory if you have already used NVM to install Node.js &/or NPM, using the common cmd...

~/$> ls ~/.nvm
~/$> ls ~/.nvm/versions
~/$> ls ~/.nvm/versions/node
~/$> ls ~/.nvm/versions/npm (use this only if you have NPM versions)

Listing the directories will familiarize you with your Linux OS, with NVM, & with Node.js.

Inside the directory, you should have found each version you installed of Node.js & NPM.



Step #2


Currently the node version is 17.5.0 at the time of writing this.

...so, at the time of writing this, when I install the latest Node Version I will perform the next step like this.

~/$> cd ~/.nvm/versions/node/17.5.0

You will want to replace 17.5.0 with what ever version your working with.

You should now have your consoles cmdLine pointed at the current Node.js version's directory that you installed using NVM.

use ~/$> ls . to veiw the contents.

You should see a bin dir listed, go ahead and use:

~/$> cd bin from within the nvm-node directory...

Alternatively you can use the following from whatever directory your in

~/$> cd ~/.nvm/versions/node/17.5.0/bin

Once inside your nodes bin directory, use ~/$> ls -1 . \

You should see a couple symbolic links, and a node executable. In my terminal (which uses the standard ANSI Linux color scheme) the node executable is highlighted green.

It will simply be called node, but it won't be a directory.

preform this command

~/$> sudo cp ./node /usr/bin/node

That copies the executable, which cannot be linked using the ln -s ... command into your binaries.

Now if you use node -v you will have the latest version.




Donniedonnish answered 19/2, 2022 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.