public

Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo. Use this first: apt-get install g++ curl libssl-dev

  • Download Gist
node-and-npm-in-30-seconds.sh
Shell
1 2 3 4 5 6 7 8 9
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
only-git-all-the-way.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# this way is best if you want to stay up to date
# or submit patches to node or npm
 
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
 
# could also fork, and then clone your own fork instead of the official one
 
git clone git://github.com/joyent/node.git
cd node
./configure --prefix=~/local
make install
cd ..
 
git clone git://github.com/isaacs/npm.git
cd npm
make install # or `make link` for bleeding edge
take-ownership.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# take ownership of the folders that npm/node use
# please don't do this if you don't know what it does!
sudo mkdir -p /usr/local/{share/man,bin,lib/node,include/node}
sudo chown -R $USER /usr/local/{share/man,bin,lib/node,include/node}
 
# now just a pretty vanilla node install
# let it use the default paths, but don't use sudo, since there's no need
mkdir node-install
curl http://nodejs.org/dist/node-v0.4.3.tar.gz | tar -xzf - -C node-install
cd node-install/*
./configure
make install
 
# now the npm easy-install
curl http://npmjs.org/install.sh | sh
use-nave-no-shell.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# use nave, but without a subshell
# note that we're doing "usemain" instead of "use"
 
mkdir ~/.nave
cd ~/.nave
wget http://github.com/isaacs/nave/raw/master/nave.sh
sudo ln -s $PWD/nave.sh /usr/local/bin/nave
 
# take ownership
# please don't do this if you don't know what it does!
sudo mkdir -p /usr/local/{share/man,bin,lib/node,include/node}
sudo chown -R $USER /usr/local/{share/man,bin,lib/node,include/node}
 
# install the latest stable nodejs in the "main" root.
nave usemain stable
 
curl http://npmjs.org/install.sh | sh
use-nave.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# this way is really handy if you want to test things
# in different versions of node and use stable release
# versions of things.
 
# make a folder where you want to keep this stuff.
 
mkdir ~/.nave
cd ~/.nave
wget http://github.com/isaacs/nave/raw/master/nave.sh
sudo ln -s $PWD/nave.sh /usr/local/bin/nave
 
# now you can forget about that folder.
# you never have to go back in there.
 
# to use a version of node in a virtual environment
nave use 0.2.3
 
# to install npm in that virtualenv
curl http://npmjs.org/install.sh | sh
 
# do stuff...
npm install whatever etc
 
# return to non-nave-land
exit
 
# use a different version of node..
nave use 0.2.1
# etc...
using-homebrew.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# using Homebrew
 
# Note: `brew install npm` has problems, as of 2010-12-30.
# hopefully it will eventually be good and happy.
# As of npm@0.2.13, however, this is an option
 
PREFIX=$(brew --prefix)
 
# take ownership
# this will also let homebrew work without using sudo
# please don't do this if you don't know what it does!
sudo mkdir -p $PREFIX/{share/man,bin,lib/node,include/node}
sudo chown -R $USER $PREFIX/{share/man,bin,lib/node,include/node}
 
brew install node
 
# add prefix/lib/node to your NODE_PATH, because it won't
# be picked up by default in a brew install of node.
if ! [ "x$NODE_PATH" = "x" ]; then
NODE_PATH="${NODE_PATH}:"
fi
echo 'export NODE_PATH=$NODE_PATH'$PREFIX'/lib/node' >> ~/.bashrc
. ~/.bashrc
 
# now install npm
curl http://npmjs.org/install.sh | sh
using-isaacs-homebrew.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# using Homebrew
 
PREFIX=$(brew --prefix)
 
# do this to get just the npm recipe from my homebrew fork.
cd $PREFIX
git remote add isaacs git://github.com/isaacs/homebrew.git
git fetch -a isaacs
git checkout isaacs/master -- Library/Formula/npm.rb
 
# alternatively, you could also do this if you prefer to avoid git:
# curl https://github.com/isaacs/homebrew/raw/master/Library/Formula/npm.rb > $PREFIX/Library/Formula/npm.rb
 
brew install npm
 
# now do ALL the things that it says to do, or it won't work properly!
xgd-freedesktop.org-style.sh
Shell
1 2 3 4 5 6 7 8 9 10
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
echo 'export npm_config_userconfig=$HOME/.config/npmrc' >> ~/.bashrc
. ~/.bashrc
mkdir ~/.local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/.local
make install
curl http://npmjs.org/install.sh | sh
yet-another-option.sh
Shell
1 2 3 4 5 6 7 8 9
# install node wherever.
# use sudo even, it doesn't matter
# we're telling npm to install in a different place.
cat <<NPMRC >>$HOME/.npmrc
root = ~/.node_libraries
manroot = ~/local/share/man
binroot = ~/bin
NPMRC
curl http://npmjs.org/install.sh | sh

before installing run this to make sure that you have needed dependencies:

apt-get install g++ curl libssl-dev apache2-utils

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.