Skip to content

Instantly share code, notes, and snippets.

@chriswoodle
Last active May 14, 2018 18:32
Show Gist options
  • Save chriswoodle/47b803974e22e5e40083b8e7a1bef2a5 to your computer and use it in GitHub Desktop.
Save chriswoodle/47b803974e22e5e40083b8e7a1bef2a5 to your computer and use it in GitHub Desktop.
#!/usr/bin/sudo bash
# This script finds, downloads and installs the latest version of nodejs for linux x64.
# This script is designed to be safe to rerun.
sudo -v
VERSION="$(wget -q -O- https://nodejs.org/dist/latest/ | \
grep -o -E "node-v[0-9]+\.[0-9]\.[0-9]-linux-x64" | \
head -n1)"
echo Installing $VERSION\.\.\.
wget -q https://nodejs.org/dist/latest/$VERSION\.tar\.gz -P /tmp
tar -xf /tmp/$VERSION\.tar\.gz -C /tmp
sudo cp -R /tmp/$VERSION/{bin,include,lib,share} /usr/local/ > /dev/null
rm -rf /tmp/$VERSION*
mkdir ~/.npm-global 2> /dev/null
npm config set prefix '~/.npm-global'
if ! grep -q "export PATH=~/.npm-global/bin:\$PATH" ~/.bashrc; then
# Only add to .bashrc if its not there
echo "export PATH=~/.npm-global/bin:\$PATH" >> ~/.bashrc
fi
echo Done\.
node -v
npm -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment