Skip to content

Instantly share code, notes, and snippets.

@NerdDiffer
Last active May 23, 2016 23:36
Show Gist options
  • Save NerdDiffer/c62bb9420180d9b716c6 to your computer and use it in GitHub Desktop.
Save NerdDiffer/c62bb9420180d9b716c6 to your computer and use it in GitHub Desktop.
install node & npm in 30 seconds

Installing node & npm in 30 seconds

Link to node-and-npm-in-30-seconds.

Those direction are a little outdated: the script assumes python2 is the default Python on the system. With this little tweak, you can install node as prescribed in the gist above by symlinking python to python2.

The benefit is that it may save you the trouble of combing through the comments thread in the original gist.

This only concerns the first gist. It's tested on Manjaro (based on Arch Linux), but it'll likely address the same issue for any Linux system that uses Python3 as default. I've used it myself from late 2014 onwards without problems.

  • Add the following file to your home directory, inspect it.
  • Update its permissions to executable: chmod +x install-node.sh
  • Then let it go: ./install-node.sh
#!/bin/bash
cd $HOME
LOCAL_DIR=$HOME/local
NODE_DIR=$HOME/node-latest-install
echo 'export PATH=$HOME/local/bin:$PATH' >> $HOME/.bashrc
. $HOME/.bashrc
mkdir $LOCAL_DIR
mkdir $NODE_DIR
# download a version of Node
cd $NODE_DIR
read -p "Which version of NodeJS? " V
if [ -z "$V" ]; then
V="latest"
else
V="v$V"
fi
ZIPPED_NODE_SRC=https://nodejs.org/dist/$V/node-$V.tar.gz
curl $ZIPPED_NODE_SRC | tar xz --strip-components=1
# point whatever your python version is, to python2
PYTHON2=/usr/bin/python2
if ! [ "$(readlink $LOCAL_DIR/bin/python)" = $PYTHON2 ]; then
cd $LOCAL_DIR/bin
ln -s $PYTHON2 ./python
fi
# build & install
cd $NODE_DIR
./configure --prefix=$LOCAL_DIR
make install # this will probably take more than 30 seconds...
curl -L https://npmjs.com/install.sh | sh
# clean up the symlink for python2
if [ "$(readlink $LOCAL_DIR/bin/python)" = $PYTHON2 ]; then
cd $LOCAL_DIR/bin
rm ./python
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment