Last active
May 14, 2018 18:32
-
-
Save chriswoodle/47b803974e22e5e40083b8e7a1bef2a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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