Last active
February 11, 2016 22:03
-
-
Save risyasin/a61aea0e5fa88d635f59 to your computer and use it in GitHub Desktop.
Ubuntu Server install Node.js proper way
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/env bash | |
NODEJS_VERSION=5.6.0 | |
# aria2 is a really nice tool. promise, you won't regret | |
apt-get install -y aria2 | |
echo "Installing Node.js v${NODEJS_VERSION} to /opt/nodejs" | |
cd /opt/ | |
## cleanup | |
rm -rf /opt/nodejs | |
rm -rf /opt/node-v${NODEJS_VERSION}-linux-x64 | |
## download & extract | |
aria2c https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-linux-x64.tar.gz | |
tar zxvf node-v${NODEJS_VERSION}-linux-x64.tar.gz | |
## rename it to /opt/nodejs | |
mv node-v${NODEJS_VERSION}-linux-x64 nodejs | |
## cleanup | |
rm -rf node-v${NODEJS_VERSION}-linux-x64.tar.gz | |
rm -rf /usr/bin/node | |
rm -rf /usr/bin/npm | |
## link executables in case of profile.d fails | |
ln -s /opt/nodejs/bin/node /usr/bin/node | |
ln -s /opt/nodejs/bin/npm /usr/bin/npm | |
## add paths via profile.d | |
rm -f /etc/profile.d/nodejs-${NODEJS_VERSION}.sh | |
echo "export NODE_BIN=/opt/nodejs/bin" >> /etc/profile.d/nodejs-${NODEJS_VERSION}.sh | |
echo "export NODE_PATH=/opt/nodejs/lib/node_modules" >> /etc/profile.d/nodejs-${NODEJS_VERSION}.sh | |
echo "export PATH=\"\$PATH:\${NODE_BIN}\"" >> /etc/profile.d/nodejs-${NODEJS_VERSION}.sh | |
## apply nodejs | |
source /etc/profile.d/nodejs-${NODEJS_VERSION}.sh | |
echo "Node.js is installed: `node -v`" | |
echo "NPM is installed: `npm -v`" | |
echo "Installing Generic Nodejs Modules" | |
## these are also useful. | |
/opt/nodejs/bin/npm install -g bower | |
/opt/nodejs/bin/npm install -g gulp-cli | |
/opt/nodejs/bin/npm install -g forever | |
echo "Done. Have a nice day!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ready?
curl -fsSL https://gist.githubusercontent.com/risyasin/a61aea0e5fa88d635f59/raw/4a2d33917537432a119b31965238e2e6edab9f19/install-nodejs.sh | bash