$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt install git-core zsh autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev -y
$ sudo apt-add-repository ppa:git-core/ppa && sudo apt-get update && sudo apt-get install git -y
$ git config --global user.name "User Name"
$ git config --global user.email [email protected]
$ git config --global core.editor vim # You might prefer nano or something else?
$ git config --global alias.ci commit
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.st status
$ git config --global alias.last 'log -1 HEAD'
$ git config --global core.excludesfile ~/.gitignore_global
$ touch ~/.gitignore_global
$ vim ~/.gitignore_global
*.lock
*.tmp
# Logs and databases #
*.log
*.sql
*.sqlite
# OS generated files #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
$ sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ sudo apt-get install fonts-powerline
If installing Ubuntu on Windows 10, download and install DejaVuSansMono for Powerline font and install on Windows 10 so we can select the font in our Ubunutu shell:
https://github.com/powerline/fonts/tree/master/DejaVuSansMono
$ vim ~/.zshrc
ZSH_THEME="agnoster"
$ cd ~/.oh-my-zsh/themes
$ vim agnoster.zsh-theme
Comment out prompt_context and change PROMPT variable
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
# prompt_context
prompt_dir
prompt_git
prompt_bzr
prompt_hg
prompt_end
}
PROMPT='$(build_prompt) '
$ cd ~/.oh-my-zsh/custom/plugins
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting
$ git clone https://github.com/zsh-users/zsh-autosuggestions
$ vim .zshrc
plugins=(
bundler
colored-man-pages
git
rake
rails
rbenv
ruby
zsh-syntax-highlighting
zsh-autosuggestions
)
$ chsh -s $(which zsh)
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ ~/.rbenv/bin/rbenv init
$ echo "eval "$(rbenv init -)"" >> .zshrc
Now source the .zshrc file and confirm rbenv is installed
$ cd ~
$ source .zshrc
$ type rbenv
rbenv is a shell function from /home/user/.zshrc
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install 2.5.1
$ rbenv global 2.5.1
Set up your .gemrc file to skip documentation when installing gems:
$ vim ~/.gemrc
$ echo "gem: --no-document" >> ~/.gemrc
$ gem install awesome_print
$ touch ~/.irbrc
require 'rubygems'
require 'irb/completion'
require 'ap'
# Easily print methods local to an object's class
class Object
def local_methods
(methods - Object.instance_methods).sort
end
end
# Alias for exit
alias q exit
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = 1000
$ gem install bundler
$ gem install rails
$ rbenv rehash
Now create ~/.railsrc with as many default options as you like!
$ vim ~/.railsrc
--database=postgresql
#--webpack
#--skip-action-cable
#--skip-coffee
#--skip-spring
#--skip-turbolinks
#--template=~/rails_template.rb
$ curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
$ sudo bash nodesource_setup.sh # Yes, even if you are using ZSH!
$ sudo apt-get install nodejs -y
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn -y
$ sudo apt-get install postgresql postgresql-contrib libpq-dev -y
$ sudo service postgresql start
Postgres by default uses template1 with SQL_ASCII encoding - we need to switch this to UTF-8 to avoid errors with creating databases for our Rails app. Credit to amolkhanorkar: https://gist.github.com/amolkhanorkar/8706915
$ sudo -u postgres psql
\l # will show you a list of databases, including template1
We need to DROP and then recreate template1 but templates can’t be dropped, so we first 'convert it' to an ordinary database:
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
Now we can drop it:
DROP DATABASE template1;
Now its time to recreate template1 from template0, with a new default encoding (UTF8):
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
Now modify template1 so it’s actually a template:
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
template1 should now show as having UTF8 as it's encoding when you type \list
. Now connect to template1 and VACUUM FREEZE it:
\c template1;
VACUUM FREEZE;
Next up, we create a new role to work with your rails development and test databases and quit Postgres
CREATE ROLE rolename WITH CREATEDB;
ALTER ROLE rolename WITH LOGIN;
\q # quit Postgres
$ createdb myrailsapp_development
$ createdb myrailsapp_test
Congratulations, you now have Rails 5.2.0, Ruby 2.5.1 and Postgres 9.5.13 set up on Ubuntu 16.04LTS along with a shiny Z shell!
sudo apt-get autoremove