45

I have downloaded Node.js from this link, which points to this link when clicking the button:

https://nodejs.org/dist/v4.1.2/node-v4.1.2-linux-x64.tar.gz

As advice from the Ubuntu community on installing the tar.gz, the following steps are followed.

$ ./configure
$ make
$ [sudo] make install

The problem is the current file I have downloaded does not contain ./configure.

So how do I install this? Should I extract this to the usr/ folder?

My OS is Debian 8 (Jessie).

Should I include the Java package from Oracle? Is it safe to extract these files to the /usr folder?

12 Answers 12

59

You can download this file from the browser or from the console. The latter is shown below (note: the specific Node.js version might be different for you):

Example :

wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz

sudo tar -C /usr/local --strip-components 1 -xzf node-v8.1.1-linux-x64.tar.gz

 #tar options:

 -x, --extract, --get
   extract files from an archive

 -f, --file ARCHIVE
   use archive file or device ARCHIVE

 -z, --gzip, --gunzip --ungzip`

You may find list of node version on http://nodejs.org/dist/

You should now have both Node.js and npm installed in “/usr/local/bin”. You can check this typing:

ls -l /usr/local/bin/node ls -l /usr/local/bin/npm

*An alternative way to install Node.js via the package manager:

Installing Node.js via package manager

6
  • 1
    I see. i should use /usr/local. should java be extracted there also?
    – user101
    Commented Oct 9, 2015 at 9:00
  • 1
    Do not wget 0.12.0, its not stable and its pretty old.
    – tsturzl
    Commented Oct 9, 2015 at 10:18
  • @tsturzl Added new version and location of node packages :) Commented Jun 14, 2017 at 13:20
  • 10
    sudo tar -C /usr/local --strip-components 1 -xf node-v8.1.1-linux-x64.tar.xz For xz archieve
    – Nilesh
    Commented Jul 24, 2018 at 19:18
  • How to remove after installing, if i wish to remove
    – Rahul
    Commented Sep 18, 2021 at 4:06
26

As @mckenzm had pointed out the approach of dumping the contents of the archive into the in-path folders like /usr/local/bin/ is not a great one. You will be in a lot of trouble when you have to remove this and upgrade to the next version due to some security issue.

The following are two approaches to follow

Manual installation

The approach to follow is to keep it in a way that it is easy to remove and upgrade, the way to do it is to keep all the stuff in one place and add that place to your path, for that One can do

sudo tar -xf node-v20.11.0-linux-x64.tar.xz --directory=/opt/

and add the bin folder to your $PATH variable using the following

echo 'export PATH="/opt/node-v20.11.0-linux-x64/bin/:$PATH"' >> ~/.bashrc && source ~/.bashrc

This is a better approach because you can remove it, and upgrade it easily compared to just dumping all the files in the /bin folder, like many, including my previously written answer ( deleted now ), are telling.

Now on any given day, you can remove the entire folder from /opt and replace it with the version you want or even you can use multiple versions at the same time.

Using tools like nvm

node version manager is a tool, that can be very useful, specially for personal use, when you might need more than one version, you can install it via reading the documentation - it is very simple to do and nvm is a very useful script - for more visit https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script

If you ask me, I prefer the nvm approach.

5
  • This way only node is being installed, not npm node -v -> v14.17.6 , npm -v -> bash: /snap/bin/npm: No such file or directory
    – Rahul
    Commented Sep 18, 2021 at 4:09
  • npm comes with node, you don't have to install it differently. Commented Sep 26, 2021 at 13:42
  • there is no bin nor sbin folder in the current node-v18.17.0.tar.gz - do we still need to MAKE?
    – mckenzm
    Commented Jul 31, 2023 at 4:05
  • @mckenzm you don't need to build anything, its build already, just download the Linux binary, not the source code. IF you are planning to build on your own, then read the readme.md file within the source code. Commented Jul 31, 2023 at 6:16
  • 1
    @Ace - I might have downloaded from the landing page (sans linux in the name) rather than the binaries on the "download" page - the .bat Android, and mainframe content should have been a clue. I am sure I am not the only one doing this.
    – mckenzm
    Commented Aug 1, 2023 at 0:50
7

In case of installing from source code, you must download source code from https://nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz.

The file ending with .tar.gz is the compressed file like zip file, and you should extract the file before you can do another operation.

You can extract this file anywhere you need. In the terminal, change the location to your .tar.gz file:

$ cd /path/to/tar.gz/file

Then extract it using tar:

$ tar xvzf node-v4.1.2.tar.gz

Then change the location to the extracted directory

$ cd node-v4.1.2

After this, you can run .configure and 'make' it:

$ ./configure
$ make
$ [sudo] make install
5
  • 8
    if you download the current file i linked you wouldn't fine any ./configure
    – user101
    Commented Oct 9, 2015 at 8:54
  • Sorry, for my mistaken. The file you download is not the source code please download source code from nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz Commented Oct 9, 2015 at 9:01
  • 1
    After download the source code you will found configure file Commented Oct 9, 2015 at 9:06
  • it's ok buddy. but how do i install the one they have given?
    – user101
    Commented Oct 9, 2015 at 9:13
  • the command '[sudo] make install' will install your built package automatically. Commented Oct 9, 2015 at 9:19
6

Run the following commands where your ta.xz file (no need for extraction) file is located in the terminal. NB: I used Kali Linux

sudo mkdir -p /usr/local/lib/nodejs

sudo tar -xJvf node-v14.4.0-linux-x64.tar.xz -C /usr/local/lib/nodejs

export PATH=/usr/local/lib/nodejs/node-node-v14.4.0-linux-x64/bin:$PATH

You can now check npm -v, node -v, and npx -v.

1
  • Thank you Peter and Amold , It worked for me as well at v14.16.0 LTS Commented Feb 24, 2021 at 19:00
5

Using the make utility is only necessary if you're compiling software. However, the tarballs provided by nodejs.org contain compiled binaries, not source code. Really you don't need to install it to use.

You can simply cd into the bin directory and run it via ./node. Though I'll say it's pretty useful to have it in your PATH. Where you put this directory doesn't really matter.

If you're installing it locally on your own machine, you can just untar it, tar xvfz node*tar.gz, to your home directory, add this to the file ~/.bashrc, and append the directory path your your PATH environment variable like so PATH=$PATH:/home/USERNAME/DIRECTORY/bin. Just change the path to the exact path to the bin folder in the directory you extracted.

You can also add these files to a directory that's already in your path, such as /usr/share or /usr/local by simple copying the files from the archive into these folders, as they share the same structure.

4
  • thanks for the explnation. which should i use? /usr/share or /usr/local?
    – user101
    Commented Oct 9, 2015 at 9:20
  • what happens if two different version of node are installed on those folders?
    – user101
    Commented Oct 9, 2015 at 9:24
  • 1
    Either works the same essentially. However it makes more sense to do /usr/local because its meant for these kinds of things. Either way they're both in your PATH already. Basically the PATH is a variable with mulitple paths to binary locations which can be used as commands. If you look in /usr/bin and /bin you'll find an executable for every shell command. So having something in your path simply means that its an executable in one of the directories in your PATH variable. If you're interested take a look at echo $PATH.
    – tsturzl
    Commented Oct 9, 2015 at 10:20
  • Since "node" is the binary file in the package, so I copied it to /usr/bin/, but npm is a JS file. Will copying npm to /usr/bin/ also work? I think it should need to be run as node npm?
    – nvkrj
    Commented Sep 9, 2018 at 9:54
3

STEP 1:

Download your version of Node.js from the Node.js website or use the below command with your version:

wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz

You will get a Node.js file tar file after the above step.

STEP 2:

Just use the below command for installation

sudo tar -C /usr/local --strip-components 1 -xvf node-v8.1.1-linux-x64.tar.gz
0
2

I am mentioning version-specific installation of NVM and Node.js.

If you don't have brew installed, run this:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

If you don't have wget installed, run this:

brew install wget

To install Node.js of a specific version, run these commands: Here, I'm installing NVM - v0.33.1 and Node.js of v0.12.6.

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

source ~/.bashrc

nvm install v0.12.6

command -v nvm  //verify install
2

You can do some this:

# Using Ubuntu or Debian
curl -sL https://deb.nodesource.com/setup_[version].x | sudo -E bash -
sudo apt-get install -y nodejs

Where [version] must be replaced for your version of Node.js that you required install

For example, I required to install Node.js v.12

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

Download a suitable installation from https://nodejs.org/en/download/

Incase of CentOS

  1. Go to the downloaded file location

  2. Execute the following sudo tar -C /usr/local --strip-components 1 -xf "name of the tar.xz downloaded"

  3. Check the installed version is correct node --version

1

nodejs.org downloads

Inspect the download. If it does not have bin or sbin folders it is *source". So assuming you have downloaded it somewhere under ~ just extract it, cd into the folder and go from there. If you have to, create a temporary folder.

You won't have (or should not have) permissions in /usr/local and unzipping into /usr/local is very hard to back out. I have not reported the answers above as malicious, because they were written for specific files. But never just blindly unzip into a folder structure.

0

The given solution is correct, but it works for the source file and not the Linux distribution link used in the question above.

$ ./configure
$ make
$ [sudo] make install

The correct link is: https://nodejs.org/dist/v8.11.2/node-v8.11.2.tar.gz and we can use the above steps after downloading and extracting this file.

0

Download the latest version of Node.js from the official site, https://nodejs.org/en/

Steps to install:

  1. Extract to any of the directories where you wish to install Node.js using a command or archive manager window

  2. Open the terminal

  3. Run '$sudo su'

  4. Being superuser and open the profile file using 'nano ~/.profile'

  5. At the end of the file, add:

     # Node.js
     export PATH=/path-to-bin.executable:$PATH
    

    The path to bin application located within the bin folder of Node.js extracted folder is to be pasted in the above line

  6. Save using Ctrl + O then come out by Ctrl + X

  7. Refresh profile by the command '.~/.profile'

  8. Come out of superuser by the 'exit' command

  9. Again for normal users, use 'sudo'

  10. 'sudo nano ~/.profile'

  11. Add the line at the end:

    # Node.js
    export PATH=/path-to-bin.executable:$PATH
    

    Same as in step 5

    Save and exit

  12. Here the refresh command as above won't work, so restart the system to finish installation correctly

  13. To get the version, issue 'node -v'

Not the answer you're looking for? Browse other questions tagged or ask your own question.