To install Node.JS on Ubuntu/Debian, run
apt install nodejs nodejs-legacy
Node Version Manager
Some times application need different version of Node.Js than the one provided with your OS. You can install different version of Node.Js by using Node Version Manager (nvm). You can find more details on nvm at http://nvm.sh.
To install nvm, run
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
Example
root@git:~# curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11388 100 11388 0 0 15814 0 --:--:-- --:--:-- --:--:-- 15816 => Downloading nvm from git to '/root/.nvm' => Cloning into '/root/.nvm'... remote: Counting objects: 6104, done. remote: Compressing objects: 100% (10/10), done. remote: Total 6104 (delta 2), reused 0 (delta 0), pack-reused 6094 Receiving objects: 100% (6104/6104), 1.76 MiB | 0 bytes/s, done. Resolving deltas: 100% (3765/3765), done. Checking connectivity... done. * (HEAD detached at v0.33.1) master => Compressing and cleaning up git repository Counting objects: 6104, done. Delta compression using up to 2 threads. Compressing objects: 100% (6066/6066), done. Writing objects: 100% (6104/6104), done. Total 6104 (delta 4033), reused 1890 (delta 0) => Appending nvm source string to /root/.bashrc => bash_completion source string already in /root/.bashrc => You currently have modules installed globally with `npm`. These will no => longer be linked to the active version of Node when you install a new node => with `nvm`; and they may (depending on how you construct your `$PATH`) => override the binaries of modules installed with `nvm`: /usr/local/lib `-- [email protected] => If you wish to uninstall them at a later point (or re-install them under your => `nvm` Nodes), you can remove them from the system Node as follows: $ nvm use system $ npm uninstall -g a_module => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm root@git:~#
Install Specific version of Node.js with nvm
To install specific version of Node.js with nvm, run
nvm install vVERSION-NUMBER-HERE
Example
root@git:~# nvm install v4.2.3 Downloading and installing node v4.2.3... Downloading https://nodejs.org/dist/v4.2.3/node-v4.2.3-linux-x64.tar.xz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v4.2.3 (npm v2.14.7) root@git:~# node --version v4.2.3 root@git:~#
To list all node.js version, run
root@git:~# nvm ls v4.2.3 -> v4.8.0 system default -> v4 (-> v4.8.0) node -> stable (-> v4.8.0) (default) stable -> 4.8 (-> v4.8.0) (default) iojs -> N/A (default) lts/* -> lts/boron (-> N/A) lts/argon -> v4.8.0 lts/boron -> v6.10.0 (-> N/A) root@git:~#
To use a node.js version, run
root@git:~# nvm use v4.2.3 Now using node v4.2.3 (npm v2.14.7) root@git:~# root@git:~# node --version v4.2.3 root@git:~#