Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active January 25, 2019 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/a4bac9a6ba227d1784319631fe68ae2d to your computer and use it in GitHub Desktop.
Save WillSams/a4bac9a6ba227d1784319631fe68ae2d to your computer and use it in GitHub Desktop.
NodeJS, Ruby, and .NET install script for Ubuntu 18.04 'bionic'
#!/bin/bash
# The 'get you set up w/ NodeJS, Ruby, and .NET on Linux' script
#
# Pre-req: Ubuntu Bionic (18.04) desktop or server
#
# Note: This script makes a few assumptions for you:
# 1) If you don't have RVM and Ruby installed, this script will download and source it for you.
# DO NOT EXECUTE this script if you already have Ruby installed and not currently using RVM.
# 2) If you don't have a ~/.npm-global available, this script will create it for you.
# 3) If you don't have dotnet installed, this script will create it for you.
#
# Additional notes:
# If you want to setup Nginx w/ KeystoneJS (NodeJS), see my nginx-keystone.sh gist.
# If you want to setup Nginx w/ GrandNode (.NET), see my nginx-grandnode.sh gist.
# If you want to setup Nginx w/ Rails (Ruby), see my nginx-rails.sh gist.
#
# All 3 gists require this current script and mongodb-setup.sh as a pre-requisites.
# All 3 can be executed on the same server without breaking anything once nginx is intalled.
if [ -d $HOME/.npm-global ]; then
echo "~/.npm-global exists in your path."
else
echo "********************* NODEJS & NPM INSTALL ***********************"
echo "Installing nodejs and npm. Also adding ~/.npm-global to your path"
echo "You may be prompted for root credentials to complete the install."
echo "******************************************************************"
mkdir ~/.npm-global
echo -e "export NPM_CONFIG_PREFIX=$HOME/.npm-global" >> ~/.bashrc
echo -e "PATH=$PATH:$HOME/.npm-global/bin" >> ~/.bashrc
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo bash -c "apt update && apt upgrade -y"
sudo bash -c "apt install nodejs -y"
sudo bash -c "npm config set prefix '/home/$USER/.npm-global'"
sudo bash -c "chown $USER:$USER -R $HOME/.config"
fi
if [ -d $HOME/.npm-global/lib/node_modules/yo ]; then
echo "NPM package 'yo' exists globally via ~/.npm-global"
else
echo "************************** YO INSTALL ****************************"
echo "Installing NPM package 'yo'."
echo "******************************************************************"
sudo bash -c "apt update && apt upgrade -y"
npm install -g yo
fi
if [ -d $HOME/.npm-global/lib/node_modules/pm2 ]; then
echo "NPM package 'pm2' exists globally via ~/.npm-global"
else
echo "************************* PM2 INSTALL ****************************"
echo "Installing NPM package 'PM2'."
echo "******************************************************************"
sudo bash -c "apt update && apt upgrade -y"
npm install -g pm2
fi
if [ -d $HOME/.npm-global/lib/node_modules/generator-keystone ]; then
echo "NPM package 'generator-keystone' exists globally via ~/.npm-global"
else
echo "*********************** KEYSTONE INSTALL *************************"
echo "Installing NPM package 'generator-keystone'."
echo "******************************************************************"
sudo bash -c "apt update && apt upgrade -y"
npm install -g generator-keystone
fi
if [ -d $HOME/.rvm ]; then
echo "RVM /w Ruby is not installed on your machine."
else
echo "********************** RVM & RUBY INSTALL ************************"
echo "RVM /w Ruby is not installed."
echo "You may be prompted for root credentials to complete the install."
echo "******************************************************************"
sudo bash -c "apt update && apt upgrade -y"
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable --ruby
echo -e "source $HOME/.rvm/scripts/rvm " >> ~/.bashrc
source $HOME/.rvm/scripts/rvm
gem install bundler rails
fi
if [ -f /usr/bin/dotnet ]; then
echo "Dotnet is installed on your machine."
else
echo "************************ DOTNET 2.1 INSTALL **************************"
echo "Installing .NET."
echo "You may be prompted for root credentials to complete the install."
echo "******************************************************************"
sudo bash -c "add-apt-repository universe && apt update && apt upgrade -y"
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo bash -c "dpkg -i packages-microsoft-prod.deb"
sudo bash -c "apt install apt-transport-https"
sudo bash -c "apt update && apt upgrade -y"
sudo bash -c "apt install dotnet-sdk-2.1 -y"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
echo -e "export DOTNET_CLI_TELEMETRY_OPTOUT=1" >> ~/.bashrc
fi
if [ -f /usr/bin/mongoimport ]; then
echo "MongoDB is installed on your machine."
else
echo "******************* MongoDB CLIENT TOOLS 4.0 INSTALL ********************"
echo "MongoDB Client Tools are is not installed."
echo "You may be prompted for root credentials during the install."
echo "Don't forget to set bind to 0.0.0.0 in /etc/mongod.conf on remote server."
echo "*************************************************************************"
wget -qO- https://www.mongodb.org/static/pgp/server-4.0.asc | sudo bash -c "apt-key add"
sudo bash -c "echo deb http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse > /etc/apt/sources.list.d/mongodb-org.list"
sudo bash -c "apt update && apt upgrade -y"
sudo bash -c "apt install mongodb-org-tools mongodb-org-shell -y"
fi
sudo bash -c "apt autoremove && apt clean -y"
sudo bash -c "ufw allow ssh && ufw enable"
echo "Script complete."
@WillSams
Copy link
Author

TODO: Clean up....I don't like the way I've relied on sourcing .bashrc in this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment