43

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user101
  • 475
  • 1
  • 4
  • 8

12 Answers12

56

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

Nullpointer
  • 1,895
  • 20
  • 26
  • 1
    I see. i should use /usr/local. should java be extracted there also? – user101 Oct 09 '15 at 09:00
  • 1
    Do not wget 0.12.0, its not stable and its pretty old. – tsturzl Oct 09 '15 at 10:18
  • @tsturzl Added new version and location of node packages :) – Nullpointer Jun 14 '17 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 Jul 24 '18 at 19:18
  • How to remove after installing, if i wish to remove – Rahul Sep 18 '21 at 04:06
  • @Rahul That's the problem. This approach makes an absolute dog's breakfast out of a very clean folder structure in /usr/local. In fact the make install should move to the path folders. You can build anywhere, The answer above, and the equally dodgy answer below may be confusing source for binaries. – mckenzm Jul 31 '23 at 04:22
23

Download the .tar.xz file form https://nodejs.org/en/ and then press Ctrl + Alt + T.

Then go to the destination that you downloaded your file to. For me it's my downloads folder. Then hit this command and Node.js will get installed on your system:

sudo tar -xf node-v16.0.0-linux-x64.tar.xz --directory=/usr/local --strip-components=1

This was the answer I had posted over two years ago, and here is what I recommand you right now, decompress the tarball, and keep it anywhere where your system knows ( tell it via updating $PATH ), its just a binary file, its not necessary to keep it in some specific location, you can keep it in your home directory and andd your bin folder to your bashrc or whatever shell you are using, its .rc file, and it will work just fine, at the end of the day, its just a pre-compiled binary file (inside node) nothing much.

Somebody in the comment section was saying npm, needs to be installed sepretly, this was in the early days of node back in 2012, when npm used to not ship with node, if you look inside bin folder npm binary is also there, so you dont need to install npm sepretly.

Ace
  • 1,398
  • 13
  • 24
  • 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 Sep 18 '21 at 04:09
  • npm comes with node, you don't have to install it differently. – Ace Sep 26 '21 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 Jul 31 '23 at 04: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. – Ace Jul 31 '23 at 06: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 Aug 01 '23 at 00: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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tsturzl
  • 3,089
  • 2
  • 22
  • 35
  • thanks for the explnation. which should i use? /usr/share or /usr/local? – user101 Oct 09 '15 at 09:20
  • what happens if two different version of node are installed on those folders? – user101 Oct 09 '15 at 09: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 Oct 09 '15 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 Sep 09 '18 at 09: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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MKDR
  • 31
  • 6
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CodeShadow
  • 3,503
  • 1
  • 17
  • 16
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kevin Mendez
  • 651
  • 5
  • 10
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

tintu
  • 11
  • 1
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
K_3
  • 83
  • 5
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'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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.

mckenzm
  • 1,545
  • 1
  • 12
  • 19