1
0
Fork 0
mirror of https://github.com/sbrl/bin.git synced 2018-01-10 21:33:46 +00:00
bin/node-update

28 lines
891 B
Text
Raw Permalink Normal View History

2015-12-11 10:29:22 +00:00
#!/bin/bash
echo "> Getting latest version number"
VERSION=v${1:-$(curl https://nodejs.org/dist/index.json | sed -e 's/^.*"version":"\([^"]*\)".*$/\1/' | head -n 2 | tail -n -1 | cut -c 2-)}
NODEJS=node-${VERSION}-linux-x64
echo "> Downloading $VERSION of node.js"
curl -s https://nodejs.org/dist/${VERSION}/${NODEJS}.tar.xz | tar xvfJ -
echo "> Setting ownership of /usr/local to $USER"
sudo chown -R ${USER}:${USER} /usr/local
echo "> Moving extracted node.js binaries"
2017-06-23 20:34:21 +00:00
if [ "$(pwd)" != "/usr/local/lib" ]; then
2017-06-09 12:11:20 +00:00
rm -rf /usr/local/lib/${NODEJS} && mv ${NODEJS} /usr/local/lib
fi
2015-12-11 10:29:22 +00:00
echo "> Symlinks"
sudo rm -f /usr/local/bin/{iojs,node,npm,node-gyp}
ln -s /usr/local/lib/${NODEJS}/bin/node /usr/local/bin/node
ln -s /usr/local/lib/${NODEJS}/bin/npm /usr/local/bin/npm
2017-06-23 20:34:21 +00:00
echo "> Global prefix"
npm config set prefix /usr/local
2015-12-11 10:29:22 +00:00
echo "node.js version: $(node -v), npm version: $(npm -v)"