in Nov 2016 I’ve published article Setup Ubuntu 16.04 for Ruby on Rails app (Cheatsheet) and it was quite a hit. As I’m reinstalling by Lenovo with fresh Ubuntu 18.04 I’ve decided to write up fresh revised article related to latest Feb 2019 technologies

Basic tools:

sudo apt install -y curl git

Generate ssh key

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Install RVM + Ruby

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
sudo apt-get install software-properties-common
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sudo apt-get install rvm

As a next step RVM recommends to configure terminal to run “Login shell”:

At terminal window, click Edit > Profile Preferences, click on Title and Command tab and check Run command as login shell. source of info

But to be honest because I use Cinnamon IDE I didn’t have to do it it works ok without. I just needed do a laptop restart othewise I’ll get rvm command not found

rvm install 2.5.3

Install PostgreSQL 10.6

at the time Postgres 11.2 is available but since AWS RDS is only supporting 10.6 I don’t see the point going super edge.

# works without adding sources
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev
psql --version                      # psql (PostgreSQL) 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1)

setup Postgres user

https://github.com/equivalent/scrapbook2/blob/master/postgresql.md

# bash
sudo -u postgres psql 
# inside psql

CREATE USER myuser WITH PASSWORD 'myPassword';

# if you want him to be superuser
ALTER USER myuser WITH SUPERUSER;

# if you just want him to be able to create DB
ALTER USER myuser WITH CREATEDB;

be sure to set credentials in config/database.yml inside your Rails project and now you can run rake db:create or rake db:migrate

Install Redis

sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server
redis-server --version     # Redis server v=5.0.3 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=45d60903d31a0894

Install MongoDB

Mongod v v3.6.3

# works without adding sources
sudo apt-get update
sudo apt install mongodb
sudo systemctl start mongodb

If you want Mongo DB v 4 check https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Install Elasticsearch

ES 7

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-18-04

sudo apt-get update

# install java
sudo apt-get install default-jre  default-jdk
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt update
sudo apt install elasticsearch

sudo systemctl status elasticsearch.service  # status
sudo systemctl start elasticsearch.service   # start server
sudo systemctl stop elasticsearch.service    # stop server

curl -X GET "localhost:9200"

To disable anoying security warning msg:

warning: 299 Elasticsearch-7.14.0-dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1 "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-minimal-setup.html to enable security."

add line xpack.security.enabled: false to file /etc/elasticsearch/elasticsearch.yml (restart es)

ES 6

https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-logstash-and-kibana-elastic-stack-on-ubuntu-18-04

sudo apt-get update

# install java
sudo apt-get install default-jre  default-jdk
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
sudo apt update
sudo apt install elasticsearch

sudo systemctl status elasticsearch.service  # status
sudo systemctl start elasticsearch.service   # start server
sudo systemctl stop elasticsearch.service    # stop server

curl -X GET "localhost:9200"

Docker

Main ref:

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce

# add your user to docker user group (so you don't have to sudo all the time)
sudo groupadd docker
sudo usermod -aG docker $USER
# ...now log out and log back in

other ref:

Docker compose

sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version    # docker-compose version 1.24.1, build 1110ad01

Imagemagic

if you need image processing inside your Rails app with gems like Carrierwave, ActiveStorage or Dragonfly

sudo apt-get update
sudo apt-get install  imagemagick libmagickcore-dev libxslt-dev libmagickwand-dev

vips

ActiveStorage in Rails 6 is using gem image_processing which requires vips lib

  • https://github.com/libvips/libvips/wiki/Build-for-Ubuntu
sudo apt install libvips libvips-dev libvips-tools

error1

https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers

FATAL: Listen error: unable to monitor directories for changes.
Visit https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers for info on how to fix this.

solution

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Ok that’s it end of article. Down bellow is just some additional software you may need (or not)

DevOps tools

Heroku Toolbelt

https://devcenter.heroku.com/articles/heroku-cli

sudo snap install --classic heroku

AWS CLI

sudo apt update
sudo apt install awscli

AWS ElasticBenstalk CLI

sudo apt install python-pip
pip install awsebcli --upgrade --user

add this to your .bash.rb

export PATH=~/.local/bin:$PATH

Azure CLI

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest

sudo apt-get install apt-transport-https lsb-release software-properties-common dirmngr -y
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-key --keyring /etc/apt/trusted.gpg.d/Microsoft.gpg adv --keyserver packages.microsoft.com  --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF
sudo apt-get update
sudo apt-get install azure-cli

Ansible

sudo apt-get update
sudo apt install ansible

note this install ansible-vault as well

Node & NPM

sudo apt-get update
sudo apt install nodejs
sudo apt install npm

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04

This way you will install Node 8.10

If you need to install different version you can use n Node version manager https://github.com/tj/n

sudo npm install -g n

example usage: sudo n 10.16.0 more info: https://github.com/tj/n#installing-node-versions

get current version node -v

YARN

https://yarnpkg.com/lang/en/docs/install/#debian-stable

curl -sS 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

My personal favorite utilities

# vim
sudo apt install -y  vim vim-gnome

# 7 zip full for encrypting file archives
sudo apt install p7zip-full

Visualized Workspaces

Visualized Workspaces is a flow I’ve invented and makes me super productive. Recommending to everyone

sudo apt install gnome-tweak-tool

follow instructions on https://blog.eq8.eu/til/visualized-desktop-workspace-flow-in-ubuntu-1804.html

Janus Vim

Janus Vim is powerful extension of Vim to give it IDE like experienc

https://github.com/carlhuda/janus

curl -L https://bit.ly/janus-bootstrap | bash

Set up SSH server (Optional)

I have a history of destroying my laptops in accidents, so often I have two laptops that I keep up to date with in case I damage one. In order to do that I have SSH server on both of them so I can connect from other to it and do updates as it it was a server when needed.

So this is only optional if you need SSH server on your laptop. If you don’t then don’t do this

Given you are configuring SSH server on Laptop1:

# run on Laptop1:

sudo apt install openssh-server
sudo vim  /etc/ssh/sshd_config       # not the simmilary named /etc/ssh/ssh_config

and make sure values are set to :

PubkeyAuthentication yes
PasswordAuthentication no

Copy content of public key of the Laptop2 ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys of the Laptop1

then run this on Laptop1:

sudo systemctl restart sshd.service

now try to ssh from Laptop2 to Laptop1

Discussion