How can I add npm (node.js package manager) to the PATH? - node.js

I installed node.js like this:
cd /usr/local/bin/
git clone --depth 1 http://github.com/joyent/node.git
cd node
git checkout origin/v0.4 # optional. Note that master is unstable.
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile
Then I executed this curl http://npmjs.org/install.sh | sh to install npm. After I logged out and logged back in, npm command wasn't recognized:
[/usr/local/bin/node]# npm install now
-bash: npm: command not found
What should I add to the PATH to have npm working?

Try this:
git clone https://github.com/npm/cli
cd npm/cli
sudo make install
That advice comes from of https://github.com/isaacs/npm#readme.
It is not as cute as curl|sh, but works.

Great news : npm now comes with nodejs !

I am a beginner~, but I want be helpful.
I use centos7, and do you know yum (a tool could download and setup programs like mirosoft Windows)
First, I search keyword "node.js" at wiki.centos, I find this. https://wiki.centos.org/SpecialInterestGroup/SCLo/CollectionsList?highlight=%28node.js%29.
There are two versions of nodejs could be used at the moment, I chose the higher one.
the URL is https://www.softwarecollections.org/en/scls/rhscl/rh-nodejs4/
and the command lines are below:
# Install a package with repository for your system:
# On CentOS, install package centos-release-scl available in CentOS repository:
$ sudo yum install centos-release-scl-rh
# On RHEL, enable RHSCL repository for you system:
$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms
# 2. Install the collection:
$ sudo yum install rh-nodejs4
# 3. Start using software collections:
$ scl enable rh-nodejs4 bash

Related

Rookie error with Node.js, Johnny Five and Raspbian

I'm currently trying to communicate with Arduino through a web server created with Node.js installed on my Orange PI PC. In order to do this, I tried to use the module called johnny five, but the only output I receive is a bunch of errors.
I'm using Raspbian v0.8.0 for Orange PI PC.
I installed node v0.10.0 by using wget plus the link.
Then, I unpacked the file by using:
cd /usr/local
sudo tar xzvf ~/node-v0.10.0-linux-arm-pi.tar.gz --strip=1
The version of node is 0.10.0 and the NPM's version is 1.2.14. When I tried to update the npm with the command npm install npm -g
these errors came in
Then, I tried to install johnny-five by following the guide that I've found on the johnny-five website which is linked to Github
And this happened
If I try to run a program, many error appear saying at the top of them 'cannot find module johnny five'.
This version of node is the only one that works for me after checking many other of them.
Try and set up a more advanced version of node.js. I had success with node v4. This will update NPM/Node.
# install updates
sudo apt-get update && sudo apt-get upgrade
# install node
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
# test
node -v
npm -v
# clone the code of the project in a folder and continue normally
You can find an old version in the Heroku web:
https://node-arm.herokuapp.com/
But if you want a more recent go to https://nodejs.org/en/download/ and dowload a new one from Linux Binaries (ARM). Unzip the binary archive to any directory you wanna install Node, I use /usr/lib/nodejs:
sudo mkdir /usr/lib/nodejs
sudo tar -xJvf node-v8.9.4-linux-armv7l.tar.xz -C /usr/lib/nodejs
sudo mv /usr/lib/nodejs/node-v8.9.4-linux-armv7l /usr/lib/nodejs/node-v8.9.4
Set the environment variable ~/.profile, adding below to the end:
# Nodejs
export NODEJS_HOME=/usr/lib/nodejs/node-v8.9.4
export PATH=$NODEJS_HOME/bin:$PATH
Refresh profile:
.~/.profile
Test installation using:
node -v
and
npm version

Nodejs installed without npm?

I've just installed nodejs on Debian 7 - by apt-get install nodejs.
Nodejs seems to be working fine, but when I enter "npm" I get "command not found".
"which nodejs" points to "usr/bin" and there it is - nodejs, but there is no npm file, what went wrong?
I found a few solutions, but all of them are related to Macs
BTW, "usr/local/bin" directory is empty I believe everything should install right there?
You have several options.
If you want to continue using Debian packages, you could install npm (debian maintainers have it in a separate package).
apt-get install npm
If you want to just install npm, you can use this modification of Maxime's answer:
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
Finally, you may wish to use a different package source.
For some Linux distributions (Debian/Ubuntu and RedHat/CentOS), the latest node version provided by the distribution may lag behind the stable version. Here are instructions from NodeSource on getting the latest node, which includes npm and avoids using the problematic nodejs alias
Install npm
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
and check version
npm -v
Node.js is easy to install in Linux
create a directory nodejs inside /usr/local/lib
download nodejs
move downloaded tar.xz file inside /usr/local/lib
extract the tar.xz file and rename as like node-v8.9.4
setup environment
cd ./etc/profile.d
ls
sudo touch nodejs-env.sh
sudo atom nodejs-env.sh
where atom is my favourite editor; you can use your editor.
copy and paste below code inside nodejs-env.sh and save
export NODEJS_HOME=/usr/local/lib/nodejs/node-v8.9.4
export PATH=$NODEJS_HOME/bin:$PATH
restart you machine.
done
There were several methods to install node.js on your debian. But I prefer this one:
Setup with Debian (as root):
apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with Debian (as root):
apt-get install --yes nodejs
After that, relaunch your terminal and type "npm" in your terminal.
The problem you're facing is due the need of super user rights during the installation. As others mentioned, you could do it via the sudo command and the manual installer.
Either way, there're several ways to install node in *unix platforms in a safer way without the need of super user rights using NVM (Node Version Manager).
Steps:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
$ nvm install 0.10
Also, you can find different techniques to install node and npm without having to sudo.

How to yum install Node.JS on Amazon Linux

I've seen the writeup on using yum to install the dependencies, and then installing Node.JS & NPM from source. While this does work, I feel like Node.JS and NPM should both be in a public repo somewhere.
How can I install Node.JS and NPM in one command on AWS Amazon Linux?
Stumbled onto this, was strangely hard to find again later. Putting here for posterity:
sudo yum install nodejs npm --enablerepo=epel
EDIT 3: As of July 2016, EDIT 1 no longer works for nodejs 4 (and EDIT 2 neither). This answer (https://stackoverflow.com/a/35165401/78935) gives a true one-liner.
EDIT 1: If you're looking for nodejs 4, please try the EPEL testing repo:
sudo yum install nodejs --enablerepo=epel-testing
EDIT 2: To upgrade from nodejs 0.12 installed through the EPEL repo using the command above, to nodejs 4 from the EPEL testing repo, please follow these steps:
sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing
The newer packages put the node binaries in /usr/bin, instead of /usr/local/bin.
And some background:
The option --enablerepo=epel causes yum to search for the packages in the EPEL repository.
EPEL (Extra Packages for Enterprise Linux) is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. Epel project is not a part of RHEL/Cent OS but it is designed for major Linux distributions by providing lots of open source packages like networking, sys admin, programming, monitoring and so on. Most of the epel packages are maintained by Fedora repo.
Via http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
Like others, the accepted answer also gave me an outdated version.
Here is another way to do it that works very well:
$ curl --silent --location https://rpm.nodesource.com/setup_16.x | bash -
$ yum -y install nodejs
You can also replace the 16.x with another version, such as 18.x, 14.x, etc.
You can see all available versions on the NodeSource Github page, and pull from there as well if desired.
Note: you may need to run using sudo depending on your environment.
The accepted answer gave me node 0.10.36 and npm 1.3.6 which are very out of date. I grabbed the latest linux-x64 tarball from the nodejs downloads page and it wasn't too difficult to install: https://nodejs.org/dist/latest/.
# start in a directory where you like to install things for the current user
(For noobs : it downloads node package as node.tgz file in your directlry)
curl (paste the link to the one you want from the downloads page) >node.tgz
Now upzip the tar you just downloaded -
tar xzf node.tgz
Run this command and then also add it to your .bashrc:
export PATH="$PATH:(your install dir)/(node dir)/bin"
(example : export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")
And update npm (only once, don't add to .bashrc):
npm install -g npm
Note that the -g there which means global, really means global to that npm instance which is the instance we just installed and is limited to the current user. This will apply to all packages that npm installs 'globally'.
Simple install with NVM...
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
To install a certain version (such as 18.12.1) of Node change the last line to
nvm install 18.12.1
For more information about how to use NVM visit the docs:
https://github.com/nvm-sh/nvm
The procedure that worked for me (following these rather old instructions with a few updates):
check git is installed git --version or install it via:
sudo yum install git
install gcc and openssl:
sudo yum install gcc-c++ make
sudo yum install openssl-devel
clone the git repo into a directory called node (which you can remove later):
git clone https://github.com/nodejs/node.git
decide which version of node you want at https://github.com/nodejs/node/releases
go to the node directory just created and install node
cd node
git checkout v6.1.0 - put your desired version after the v
./configure
make
sudo make install
test that node is installed / working with either node --version or simply node (exit node via process.exit() or ^C x 2 or ^C + exit)
check the npm version: npm --version and update if necessary via sudo npm install -g npm
Optional: remove the node directory with rm -r node
Notes:
The accepted answer didn't work since sudo yum install nodejs --enablerepo=epel-testing returns the error: No package nodejs available.
...and sudo yum install nodejs --enablerepo=epel (ie without -testing) only gave very old versions.
If you already have an old version of node installed you can remove it with:
sudo npm uninstall npm -g ...since npm can uninstall itself
sudo yum erase nodejs
sudo rm -f /usr/local/bin/node
(sudo yum rm nodejs in the accepted answer won't work as rm is not a valid yum command see yum --help)
It's possible to clone the node repo via git clone git://github.com/nodejs/node.git rather than git clone https://github.com/nodejs/node.gitbut you may get a various errors (see here).
If you already have a /node dir from a previous install, remove it before using the git clone command (or there'll be a conflict):
rm -r node
If you have trouble with any sudo npm... command - like sudo: npm: command not found and/or have permissions issues installing node packages without sudo, edit sudo nano /etc/sudoers and add :/usr/local/bin to the end of the line Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin so that it reads Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
Seems no one is mentioning this. On Amazon Linux 2, official way to load EPEL is:
sudo amazon-linux-extras install epel
...then you may:
sudo yum install nodejs
See Extras Library (Amazon Linux 2)
For the v4 LTS version use:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs
For the Node.js v6 use:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
I also ran into some problems when trying to install native addons on Amazon Linux. If you want to do this you should also install build tools:
yum install gcc-c++ make
I just came across this. I tried a few of the more popular answers, but in the end, what worked for me was Amazon's quick setup guide.
Tutorial: Setting Up Node.js on an Amazon EC2 Instance
The gist of the tutorial is:
Make sure you are ssh'd onto the instance.
Grab nvm: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Active . ~/.nvm/nvm.sh
Install node using nvm nvm install 4.4.5 (NOTE: You can choose a different version. Check out the remote versions first by running $ nvm ls-remote)
Finally, test that you have installed node Node correctly by running $ node -e "console.log('Running Node.js' + process.version)"
Hopefully this helps the next person.
RHEL, CentOS, CloudLinux, Amazon Linux or Fedora:
# As root
curl -fsSL https://rpm.nodesource.com/setup_12.x | bash -
# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum install -y nodejs
I had Node.js 6.x installed and wanted to install Node.js 8.x.
Here's the commands I used (taken from Nodejs's site with a few extra steps to handle the yum cached data):
sudo yum remove nodejs: Uninstall Node.js 6.x (I don't know if this was necessary or not)
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum clean all
sudo yum makecache: Regenerate metadata cache (this wasn't in the docs, but yum kept trying to install Node.jx 6.x, unsuccessfully, until I issued these last two commands)
sudo yum install nodejs: Install Node.js 8.x
sudo yum install nodejs npm --enablerepo=epel works for Amazon Linux AMI.
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
works for RedHat.
The easiest solution is this( do these as root)
sudo su root
cd /etc
mkdir node
yum install wget
wget https://nodejs.org/dist/v9.0.0/node-v9.0.0-linux-x64.tar.gz
tar -xvf node-v9.0.0-linux-x64.tar.gz
cd node-v9.0.0-linux-x64/bin
./node -v
ln -s /etc/node-v9.0.0-linux-x64/bin/node node
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo yum -y install nodejs
Official Documentation for EC2-Instance works for me: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
1. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
2. . ~/.nvm/nvm.sh
3. nvm ls-remote (=> find your version x.x.x =>) nvm install x.x.x
4. node -e "console.log('Running Node.js ' + process.version)"
MAY 2022
I spent way too long on this. My Amazon Linux 2 configuration, running as root.
#!/usr/bin/env zsh
# https://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users
echo "=================================N=O=D=E========================================"
cd /usr/local/bin || exit 90
git clone https://github.com/nvm-sh/nvm.git .nvm
\. "/usr/local/bin/.nvm/nvm.sh"
nvm install --lts
node -e "console.log('Running Node.js ' + process.version)"
cat << "EOF" > /etc/profile.d/npm.sh
#!/usr/bin/env bash
export NVM_DIR="/usr/local/bin/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'}
EOF
chmod 755 /etc/profile.d/npm.sh
npm install -g npm
June 2022 - The system really hates when things arn't linked in the bin. Here's a small update to help if you need things accessible by other users. Admittedly adding /etc/profile.d/npm.sh is just what nvm suggests, but I find it over-rated. I think it could be removed in place of purely the ln -s. happy hacking
#!/bin/zsh
# https://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users
echo "=================================N=O=D=E========================================"
cd /usr/local/bin || exit 90
git clone https://github.com/nvm-sh/nvm.git .nvm
# this uncontrolled script has an unbound variable $HOME
# #link https://github.com/Drop-In-Gaming/dropingaming.com/runs/6437329820?check_suite_focus=true
\. "/usr/local/bin/.nvm/nvm.sh" || true
# todo - try to install 18
nvm install --lts
nvm install 17
node -e "console.log('Running Node.js ' + process.version)"
cat << "EOF" > /etc/profile.d/npm.sh
#!/usr/bin/env bash
export NVM_DIR="/usr/local/bin/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'}
EOF
echo 'source /etc/profile.d/npm.sh' >> /root/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /root/.zshrc
echo 'source /etc/profile.d/npm.sh' >> /home/ssm-user/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /home/ssm-user/.zshrc
echo 'source /etc/profile.d/npm.sh' >> /home/www-data/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /home/www-data/.zshrc
chmod 755 /etc/profile.d/npm.sh
npm install -g npm
echo "===========================WHERE==IS==NODE==========================="
which node
which npm
echo "symlinking to /usr/bin/"
if [ -e /usr/bin/node ]; then
sudo rm -f /usr/bin/node
fi
if [ -e /usr/bin/npm ]; then
sudo rm -f /usr/bin/npm
fi
sudo ln -s "$(which node)" /usr/bin/
sudo ln -s "$(which npm)" /usr/bin/
For those who want to have the accepted answer run in Ansible without further searches, I post the task here for convenience and future reference.
Accepted answer recommendation: https://stackoverflow.com/a/35165401/78935
Ansible task equivalent
tasks:
- name: Setting up the NodeJS yum repository
shell: curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
args:
warn: no
# ...
As others mentioned using epel gives a really outdated version, here is a little script I just wrote instead to add to the CI pipeline or pass it to ec2 user-data to install the latest version of node, simply replace the version with what you want, and the appropriate distro of Linux you are using.
The following example is for amazon-Linux-2-AMI
#!/bin/bash
version='v14.13.1'
distro='linux-x64'
package_name="node-$version-$distro"
package_location="/usr/local/lib/"
curl -O https://nodejs.org/download/release/latest/$package_name.tar.gz
tar -xvf $package_name.tar.gz -C $package_location
rm -rfv $package_name.tar.gz
echo "export PATH=$package_location/$package_name/bin:\$PATH" >> ~/.profile
if you want to test it in the same shell simply run
. ~/.profile
I usually use NVM to install node on server. It gives me option to install multiple version of nodejs.
Commands are given below :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
then check if it's installed properly using :
command -v nvm
after that, run this to install latest version :
nvm install node
or
nvm install 11
As mentioned in official documentation , simple below 2 steps -
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
You can update/install the node by reinstalling the installed package to the current version which may save us from lotta of errors, while doing the update.
This is done by nvm with the below command. Here, I have updated my node version to 8 and reinstalled all the available packages to v8 too!
nvm i v8 --reinstall-packages-from=default
It works on AWS Linux instance as well.
As stated in the Amazon docs (Setting Up Node.js on an Amazon EC2 Instance), just run the following commands:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install --lts
Done!

How to install a specific version of Node on Ubuntu?

I would like to install NodeJS version 0.8.18 on Ubuntu 12.04. I tried to install the newest version and then reverting to 0.8.18 by using nvm, but when I run my code apparently there is some problem with the packages installed and the two versions (latest and 0.8.18). Since I don't know how to solve that problem, I cleaned the machine from the Node installation and thought about installing directly the version I'm interested in (v0.8.18).
The n module worked for me.
Run this code to clear npm’s cache, install n, and install the latest stable version of Node:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n
To install a specific version of node:
sudo n 6.11.2
To check what version:
node -v
You might need to restart
Chris Lea has 0.8.23 in his ppa repo.
This package let you add a repository to apt-get: (You can also do this manually)
sudo apt-get install software-properties-common
Add Chris Lea's repository:
sudo apt-add-repository ppa:chris-lea/node.js-legacy
Update apt-get:
sudo apt-get update
Install Node.js:
sudo apt-get install nodejs=0.8.23-1chl1~precise1
I think (feel free to edit) the version number is optional if you only add node.js-legacy. If you add both legacy and ppa/chris-lea/node.js you most likely need to add the version.
NVM (Node Version manager)
https://github.com/nvm-sh/nvm
Advantages:
allows you to use multiple versions of Node and without sudo
is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities
downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you
Tested in Ubuntu 17.10:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
For the particular case of the most recent long term support version (recommended if you can choose):
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca
Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc. That works, but I prefer to remove the auto-added one and add my own:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
With this setup, you get for example:
which node
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
and:
which vaca
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
and if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
as mentioned at:
NodeJS require a global module/package
How do I import global modules in Node? I get "Error: Cannot find module <module>"?
so we see that everything is completely contained inside the specific node version.
For projects however, you are better off just using packages installed locally under node_modules and npx for executable to be able to have independent versions across projects, global usage is mostly for the Node executable itself and global CLI utilities not specific to any project.
Setting the NPM version
Simply:
npm install npm#6.14.13 -g
The executable is placed inside the current NVM version, so everything remains nice and isolated, e.g.:
which npm
gives something like:
/home/ciro/.nvm/versions/node/v14.17.0/bin/npm
How can I change the version of npm using nvm?
It is possible to install specific version of nodejs from nodejs official distribution with using dpkg.
Check the version of you ubuntu distribution, cat /etc/lsb-release.
Check architecture of your os, uname -m.
Download preferred version of debian package from nodejs official site.
For 4.x, https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/
For 5.x, https://deb.nodesource.com/node_5.x/pool/main/n/nodejs/
For 0.12.x, https://deb.nodesource.com/node_0.12/pool/main/n/nodejs/
Be careful to check nodejs-dbg or nodejs in filename.
For example, currently recent 4.x version is 4.2.4, but you can install previous 4.2.3 version.
curl -s -O https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
sudo apt-get install rlwrap
sudo dpkg -i nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
Try this way. This worked me.
wget nodejs.org/dist/v0.10.36/node-v0.10.36-linux-x64.tar.gz(download file)
Go to the directory where the Node.js binary was downloaded to, and then run command i.e, sudo tar -C /usr/local --strip-components 1 -xzf node-v0.10.36-linux-x64.tar.gz to install the Node.js binary package in “/usr/local/”.
You can check:-
$ node -v
v0.10.36
$ npm -v
1.4.28
In ubuntu specific version of node can be installed with help of nvm
install nvm
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
To install a particular version of node, use the command nvm install and add the number of the version.
nvm install 10.15.2
node -v
Say you want to install Node 10,
Firstly, download and execute the Node.js 10.x installer:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
This will add a source file for the official Node.js 10.x repo, grabs the signing key
Once the installer is done doing it’s thing, you will need to install (or upgrade) Node.js:
sudo apt install nodejs
version 0.10 is also avaible with this ppa
apt-add-repository ppa:chris-lea/node.js
install nodejs with:
apt-get install nodejs=0.10.25-1chl1~precise1
Thanks to my friend Julian Xhokaxhiu
I imagine many directed here are looking for this to add to a Dockerfile
RUN set -x \
&& curl -sL 'https://deb.nodesource.com/setup_16.x' | bash - \
&& apt-get -y install nodejs \
&& ln -s /usr/bin/nodejs /usr/local/bin/node
FYI, according to this page in the wiki of the nodejs github repo, Chris Lea's PPA (mentioned in several other answers) has been superseded by the NodeSource distributions as the main way of installing nodejs from source in Ubuntu:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
This is supported for the three latest (at the time of writing this) LTS versions of Ubuntu: 10.04 (lucid), 12.04 LTS (precise) and 14.04 (trusty).
I'm not sure this will help in installing an old version of nodejs, but I'm putting this here in case it helps others who needed to install a specific (newer) version of nodejs that isn't included in their distro's repositories.
yes, its a duplicate answer but I insist using n module to install a specific version(following commands installs node version 6.9.5).
npm install -g n
n 6.9.5
NOTE: you can use NVM software to do this in a more nodejs fashionway.
However i got issues in one machine that didn't let me use NVM. So i
have to look for an alternative ;-)
You can manually download and install.
go to nodejs > download > other releases
http://nodejs.org/dist/
choose the version you are looking for
http://nodejs.org/dist/v0.8.18/
choose distro files corresponding your environmment and download (take care of 32bits/64bits version).
Example: http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gz
Extract files and follow instructions on README.md :
To build:
Prerequisites (Unix only):
* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* libexecinfo (FreeBSD and OpenBSD only)
Unix/Macintosh:
./configure
make
make install
If your python binary is in a non-standard location or has a
non-standard name, run the following instead:
export PYTHON=/path/to/python
$PYTHON ./configure
make
make install
Windows:
vcbuild.bat
To run the tests:
Unix/Macintosh:
make test
Windows:
vcbuild.bat test
To build the documentation:
make doc
To read the documentation:
man doc/node.1
Maybe you want to (must to) move the folder to a more apropiate place like /usr/lib/nodejs/node-v0.8.18/ then create a Symbolic Lynk on /usr/bin to get acces to your install from anywhere.
sudo mv /extracted/folder/node-v0.8.18 /usr/lib/nodejs/node-v0.8.18
sudo ln -s /usr/lib/nodejs/node-v0.8.18/bin/node /usr/bin/node
And if you want different release in the same machine you can use debian alternatives. Proceed in the same way posted before to download a second release. For example the latest release.
http://nodejs.org/dist/latest/ -> http://nodejs.org/dist/latest/node-v0.10.28-linux-x64.tar.gz
Move to your favorite destination, the same of the rest of release you want to install.
sudo mv /extracted/folder/node-v0.10.28 /usr/lib/nodejs/node-v0.10.28
Follow instructions of the README.md file. Then update the alternatives, for each release you have dowload install the alternative with.
sudo update-alternatives --install genname symlink altern priority [--slave genname symlink altern]
Add a group of alternatives to the system. genname is the
generic name for the master link, symlink is the name of its
symlink in the alternatives directory, and altern is the
alternative being introduced for the master link. The arguments
after --slave are the generic name, symlink name in the
alternatives directory and alternative for a slave link. Zero
or more --slave options, each followed by three arguments, may
be specified.
If the master symlink specified exists already in the
alternatives system’s records, the information supplied will be
added as a new set of alternatives for the group. Otherwise, a
new group, set to automatic mode, will be added with this
information. If the group is in automatic mode, and the newly
added alternatives’ priority is higher than any other installed
alternatives for this group, the symlinks will be updated to
point to the newly added alternatives.
for example:
sudo update-alternatives --install /usr/bin/node node /usr/lib/nodejs/node-v0.10.28 0 --slave /usr/share/man/man1/node.1.gz node.1.gz /usr/lib/nodejs/node-v0.10.28/share/man/man1/node.1
Then you can use update-alternatives --config node to choose between any number of releases instaled in your machine.
To install a specific version of nodejs in Ubuntu you can use below commands, just specify and replace the version number, for example, node_12.x will fetch the latest of 12.
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
FYI the available version for raring in Chris Lea's repo is currently 0.8.25
sudo apt-get install nodejs=0.8.25-2chl1~raring1
The Node.js project recently pushed out a new stable version with the 0.10.0 release
Use the following command on Ubuntu 13x
sudo apt-get install nodejs=0.10.18-1chl1~raring1
Install nvm using the following commands in the same order.nvm stands for node version manager.
sudo apt-get update
sudo apt-get install build-essential checkinstall libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
In case the above command does not work add -k after -o- .It should be as below:
curl -o- -k https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
Then nvm ls-remote to see the available versions.
In case you get N/A in return,run the following.
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
alternatively you can run the following commands too
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Then nvm install #.#.# replacing # by version(say nvm 8.9.4)
finally nvm use #.#.#
Here is a list of available builds for debian: https://github.com/nodesource/distributions/tree/master/deb
For this example, lets assume you want version 14 (LTS at the time of writing)
We can download this script from github, execute it and install the version of node we want. For security reasons it's a good idea to read the script prior to executing it.
curl -sL https://raw.githubusercontent.com/nodesource/distributions/master/deb/setup_14.x | bash
apt-get install -y nodejs # may or may not require sudo based on your setup
I like this approach because it doesn't require extraneous dependencies like nvm to target specific versions
If you are building for a different distro or architecture you can find more builds here https://nodejs.org/dist/

Installing NPM on AWS EC2

Working on Ec2 on AWS.
I have installed Node.js and it works fine.
But the problem arises when trying to install npm.
I am using the following command to install it:
sudo curl http://npmjs.org/install.sh | sh
But the install seems to freeze...
I get "fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz" at the prompt and it stays on like this.
Have any idea what is going on here?
sudo yum install nodejs npm --enablerepo=epel
Follow this AWS Tutorial that uses Node Version Manager.
Node Version Manager (NVM) lets you install multiple versions of Node.js and switch between them.
Here are the steps:
Install NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Activate NVM
. ~/.nvm/nvm.sh
Install Node (choose version)
nvm install 15.0.0
Confirm Successful Installation
node -e "console.log('Running Node.js ' + process.version)"
To install NodeJS 6.x execute the following commands:
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Update
You can install NodeJS 7 and 8 in the same way. Just specify the version you need instead of 6 in the command above.
Update
To update to NodeJS 16 (or any other version) do the following:
rm -rf /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Simplest way to install npm/nodejs on Amazon Linux 2 ec2 isntance:
First install epel repo using amazon-linux-extras command as below:
sudo amazon-linux-extras install epel
Now install npm and nodejs as below:
sudo yum install nodejs npm
you can verify the version of node and npm as below:
node -v
npm -v
PS. I've tested this on Amazon Linux 2 AMI (HVM) ec2 instance.
This guide worked perfectly: https://tecadmin.net/install-latest-nodejs-amazon-linux/
Make sure you have make
# sudo yum install -y gcc-c++ make
Install source
# curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
Install node
# sudo yum install -y nodejs
Note - you'll have to run sudo npm install to get the installs to work.
Firstly
sudo yum install make
You can run this to get zip of desired version of node
wget https://nodejs.org/dist/v8.10.0/node-v8.10.0.tar.gz
Then you can unzip it like this
tar -xvf node-v8.10.0.tar.gz
then go in to the extracted directory and install node like this
./configure && make && sudo make install
I found his tutorial that has been very usefull to me: The last chapter explains how to install node and npm compiling it.
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/#installNode
Get the http://npmjs.org/install.sh file on your system first and then execute it directly instead of piping with curl.
Use chmod +x install.sh to make it executable
Then run ./install.sh
I did it manually. Why mess with installers that break or don't put things where I want them? Such were the problems encountered while installing *node.js" on Amazon Web Services, that a manual install was the easy way to get the result I wanted.
I want a GLOBAL install of node and npm on AWS. By that I mean install should be put in a place like /usr/bin, so that all users have access. Surprisingly, AWS apparently doesn't give support to that idea. AWS encourages using nvm, node version manager, but that seems to always install in a user directory, and not a system level directory. After being frustrated when the "rpm" solutions (mentioned elsewhere) failed, I finally decided to just do the installation manually.
In a browser, go to nodejs.org download page:
https://nodejs.org/en/download/
Find a link that says:
All download options
Click through that; it goes to an index page with a URL like:
https://nodejs.org/dist/v14.16.1/
There I looked for the name that had "linux" and "x86" in the name.
I wrote this down, or select-and-copied, to get the correct spelling.
In my case it was:
node-v14.16.1-linux-x64.tar.gz
Putting the two parts together, I got the following URL:
https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
So that's what is to be downloaded using curl.
I have a "temp" directory conveniently located in my home dir.
cd ~/temp
The download was accomplished with "curl". Note that the -o option was used to give the output file the name of my choosing. Of course, I chose to give it the same name as the web site file.
curl -o node-v14.16.1-linux-x64.tar.gz https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
Untar the downloaded file.
tar xf node-v14.16.1-linux-x64.tar.gz
Conveniently, it creates its own directory. Go there.
cd node-v14.16.1-linux-x64 || exit 1;
Observe that the delivery consists of a relatively small number of files and directories (since node_modules is dealt with as a unit).
In my case, I had an old and bad implementation still installed, so the following commands were used to move aside any junk that might happen to be in the way. Some commands errored out because the old junk didn't exist. That's ok, error while moving to -OLD just means there is nothing to move; which is good.
Note: I put all these mv (move) commands into a script file, made it executable, and ran it as sudo. The alternative is to run each line individually as sudo.
mv /usr/bin/node /usr/bin/node-OLD
mv /usr/bin/npm /usr/bin/npm-OLD
mv /usr/bin/npx /usr/bin/npx-OLD
mv /usr/include/node /usr/include/node-OLD
mv /usr/lib/node_modules /usr/lib/node_modules-OLD
mv /usr/share/doc/node /usr/share/doc/node-OLD
mv /usr/share/man/man1/node.1 /usr/share/man/man1/node.1-OLD
mv /usr/share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/node.stp-OLD
An here is the actual install. Remember, this is occurring in the untarred directory, in my case node-v14.16.1-linux-x64.
mv bin/node /usr/bin
mv bin/npm /usr/bin
mv bin/npx /usr/bin
mv include/node /usr/include
mv lib/node_modules /usr/lib
mv share/doc/node /usr/share/doc
mv share/man/man1/node.1 /usr/share/man/man1
mv share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/
That's it, all finished.
Latest version 18 has dependency I think..
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
Finally I got solution by running by running following commands.
sudo apt-get remove nodejs
nvm install 16.15.1
v16.15.1 node version and npm v v16.15.1 is installed.
For same make sure nvm is installed in your machine.
This works for me:
sudo apt install npm
Edit as my answer wasn't pertinent anymore:
Try:
curl --silent --location https://rpm.nodesource.com/setup | bash -
yum -y install nodejs
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#enterprise-linux-and-fedora-core

Resources