Created
August 31, 2018 11:24
-
-
Save chrisidakwo/5f228cb0883efdcfae1a880f80b9744b to your computer and use it in GitHub Desktop.
Just another bash script to easily install node, npm and yarn on Ubuntu/Mac using nvm
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
#!/bin/sh | |
set -e | |
# Install node and npm via nvm - https://github.com/creationix/nvm | |
# Run this script like - bash script-name.sh | |
# Define versions | |
INSTALL_NODE_VER=10 | |
INSTALL_NVM_VER=0.33.11 | |
INSTALL_YARN_VER=1.7.0 | |
# You can pass argument to this script --version 8 | |
if [ "$1" = '--version' ]; then | |
echo "==> Using specified node version - $2" | |
INSTALL_NODE_VER=$2 | |
fi | |
echo "==> Ensuring .bashrc exists and is writable" | |
touch ~/.bashrc | |
echo "==> Installing node version manager (NVM). Version $INSTALL_NVM_VER" | |
# Removed if already installed | |
rm -rf ~/.nvm | |
# Unset exported variable | |
export NVM_DIR= | |
# Install nvm | |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v$INSTALL_NVM_VER/install.sh | bash | |
# Make nvm command available to terminal | |
source ~/.nvm/nvm.sh | |
echo "==> Installing node js version $INSTALL_NODE_VER" | |
nvm install $INSTALL_NODE_VER | |
echo "==> Make this version system default" | |
nvm alias default $INSTALL_NODE_VER | |
nvm use default | |
#echo -e "==> Update npm to latest version, if this stuck then terminate (CTRL+C) the execution" | |
#npm install -g npm | |
echo "==> Installing Yarn package manager" | |
rm -rf ~/.yarn | |
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $INSTALL_YARN_VER | |
echo "==> Adding Yarn to environment path" | |
# Yarn configurations | |
export PATH="$HOME/.yarn/bin:$PATH" | |
yarn config set prefix ~/.yarn -g | |
echo "==> Checking for versions" | |
nvm --version | |
node --version | |
npm --version | |
yarn --version | |
echo "==> Print binary paths" | |
which npm | |
which node | |
which yarn | |
echo "==> List installed node versions" | |
nvm ls | |
nvm cache clear | |
echo "==> Now you're all setup and ready for development. If changes are yet totake effect, I suggest you restart your computer" | |
# Tested on Ubuntu, MacOS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment