Skip to content

Instantly share code, notes, and snippets.

@Anyoks
Last active February 6, 2018 12:01
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 Anyoks/5ecc441c011f66aaf6864b34e89d5c02 to your computer and use it in GitHub Desktop.
Save Anyoks/5ecc441c011f66aaf6864b34e89d5c02 to your computer and use it in GitHub Desktop.
Setting vagrant vm with Ubuntu 16.04 and rails working environment. ( postgres 10, Rails 5, Ruby 2.5, and RVM)
#!/bin/bash
if
[[ "${USER:-}" == "root" ]]
then
echo "This script works only with normal user, it wont work with root, please log in as normal user and try again." >&2
exit 1
fi
set -e
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# add repo for postgres installation
echo "============add repo for later postgres installation"
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "============Updates packages. Asks for your password."
sudo apt-get update -y
echo "============Installing nginx"
sudo apt-get install nginx -y
echo "============Installing Git"
sudo apt-get install git-core -y
echo "============Setting up Git"
git config --global user.name "Denn Orina"
git config --global user.email "anyoksdenn@gmail.com"
echo "============Installs packages. Give your password when asked."
sudo apt-get --ignore-missing install build-essential git-core curl openssl libssl-dev libcurl4-openssl-dev zlib1g zlib1g-dev libreadline-dev libreadline6 libreadline6-dev libyaml-dev libsqlite3-dev libsqlite3-0 sqlite3 libxml2-dev libxslt1-dev python-software-properties libffi-dev libgdm-dev libncurses5-dev automake autoconf libtool bison postgresql-9.6 postgresql-contrib libpq-dev pgadmin3 libc6-dev nodejs -y
echo "============Installs ImageMagick for image processing"
sudo apt-get install imagemagick --fix-missing -y
echo "============Installs RVM (Ruby Version Manager) for handling Ruby installation"
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "Installs Ruby"
rvm install 2.5.0
rvm use 2.5.0 --default
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
gem install rails
echo -e "\n- - - - - -\n"
echo -e "Now we are going to print some information to check that everything is done:\n\n"
echo -n "Should be rvm 1.29 or higher: "
rvm --version
echo -n "Should be ruby 2.4.1 or higher: "
ruby -v
echo -n "Should be Bundler 1.15 or higher: "
bundler -v
echo -n "Should be Rails 5.1.3 or higher: "
rails -v
echo -n "Should be NodeJS 6.11 or higher: "
node -v
echo -n "Should be sqlite 3.11 or higher: "
sqlite3 --version
echo -n "Should be ImageMagick 6.8.9 or higher: "
convert --version
echo -e "\n- - - - - -\n"
echo "If the versions match, everything is installed correctly.
Congrats!
Make sure that all works well by running the application generator command:
$ rails new testapp"
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# give vm a host name
config.vm.hostname = "dev"
# link project folders to home dir on the vm
config.vm.synced_folder ".", "/home/vagrant/discoucher"
# disable the default mounting point
# config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.network :forwarded_port, guest: 3000, host: 3000 # rails
config.vm.network :forwarded_port, guest: 9292, host: 9292 # rack
config.vm.network :forwarded_port, guest: 4567, host: 4567 # sinatra
config.vm.network :forwarded_port, guest: 1080, host: 1080 # mailcatcher
config.vm.network :forwarded_port, guest: 8888, host: 8888 # jasmine
config.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql
config.vm.network :forwarded_port, guest: 1234, host: 1234 # node
config.vm.network :forwarded_port, guest: 5432, host: 5432 # postgresql
config.vm.network :forwarded_port, guest: 6379, host: 6378 # redis
config.vm.network :forwarded_port, guest: 9200, host: 9200 # elasticsearch
config.vm.network :forwarded_port, guest: 27017, host: 27017 # mongodb
config.vm.network :forwarded_port, guest: 80, host: 8080 # apache/nginx
config.vm.provision :shell, path: 'set_up_vm.sh', keep_color: true, privileged: false
config.vm.provider 'virtualbox' do |v|
v.memory = 1024
v.cpus = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment