When i go to https://nodejs.org/en/ i can download the linux tar.xz
file (I understand this is not what is called a package).
I open the downloaded file in the Ubuntu extractor and find a directory with subdirectories bin
, lib
...
In bin
is the node binary node
. Where do I place now this node
parent directory in my system and how do I correctly link it such that entering node
on the command line calls this new node
binary?
It is recommended to install
nodejs
through thesetup
script , your system will be able to install the security update throughapt
. As you can see the warning on the official website:To install nodjs 8.x :
To install nodjs 9.x :
To answer your question you can install the tarball as follow:
It will extract the tarball to
/usr/lib/nodjs
. renamenode-v8.9.3-linux-x64
tonode
:Run the following command :
You can add the above commands to your
~/.bashrc
then runsource ~/.bashrc
.Nodejs help: How to install Node.js via binary archive on Linux?
The best you can always do is to check the official site:
https://github.com/nodejs/help/wiki/Installation
I will break it up for you in the most simple way
First line creates a folder in the given extension. Second line extracts the tar file to the given extension. Here you must note the version and the distribution of your package. For example if your file looks like node-v14.18.1-linux-x64.tar.xz. then in the second line you must replace $VERSION with v14.18.1 and $DISTRO with linux-x64. The easiest way is to use the autocomplete tool (TAB in keyboard). In other words for this particular file you should write
In your HOME folder type
You will see hidden files there, one them is .profile. Access to this file with any editor to modify it. For example
If you don't know how to use the vi editor, read other tutorials. If it is your first time using vi, you may encounter problems, e.g., your keyboard arrows may not obey you but you can easily solve this in other forums. In the file .profile write the following at the end
#Nodejs
VERSION=v14.18.1 DISTRO=linux-x64 export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
Please be careful with /, sometimes people miss typing exactly what it is given and they fail. In your case if you are using another version just change the numbers in the second line, you don't need to change other lines. Don't get confused with the last line because we have $VERSION and $DISTRO like before but in this case we keep them, they don't need to be replaced
This creates a path to your bin folder. Save the changes in .profile and update it. To update it in the terminal type
To secure the update close the terminal and open a new one. Now just type in your new terminal
Congratulations you have node and npm...
The problem when using sudo apt-get install to install node and npm is that you may be downloading incompatible versions, so although apt-get install is simple, this is much better to have compatible versions. Cheers..