Go back Ubuntu Linux

2024 set up Ubuntu 22.04 for Ruby on Rails developer (Cheatsheet)


sudo apt install -y curl git vim


RVM & Ruby


in 2024 all that is needed is to do:

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

sudo usermod -a -G rvm $USER

that is step 1 in https://github.com/rvm/ubuntu_rvm

in older Ubuntu there was bunch of other steps like add some like "source to .bashrc" or "enable login terminal" (my article, Step 2 in github.com/rvm/ubuntu_rvm) but seems in Ubuntu 22.04 all works well without this šŸ™‚


Redis


sudo snap install redis

Gnome Tweek Tools



no longer needed for "Visualized Desktop Workspaces". Vanilla Ubuntu 22.04 has fixed setting fro workspaces in `settings > multitasking`


Ubuntu 22.04 postgres setup without password same as how OSx has it

when you develop Rails app on OSx Postgresql it's default that user don't need password to create DB so your database.yml may look likeĀ 

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: myapp_development
  host: localhost
..so no user no pass

Problem is that Ubuntu PostgresĀ  (installed with standard $sudo apt-get install postgresql postgresql-contrib libpq-dev )
is more strict and requires password auth so when you runĀ 

rails db:create
you will get error
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied (ActiveRecord::ConnectionNotEstablished)

in order to get around this you need to edit file

 sudo vim /etc/postgresql/14/main/pg_hba.conf 

and have values like this

 # Database administrative login by Unix domain socket
 local   all             all                                     trust

 # TYPE  DATABASE        USER            ADDRESS                 METHOD

 # "local" is for Unix domain socket connections only
 local   all             all                                     trust
 # IPv4 local connections:
 host    all             all             127.0.0.1/32            trust
 # IPv6 local connections:
 host    all             all             ::1/128                 trust


After save

sudo service postgresql restart


credit https://gist.github.com/p1nox/4953113

Now if you runĀ 

rails db:create
you get new error

PG::ConnectionBad: connection to server at "127.0.0.1", port 5432 failed: FATAL:  role "thisisyou" does not exist (PG::ConnectionBad)

thisisyouĀ Ā is your Ubuntu user, without specifying an user in database.yml Ubuntu will use system user name as postgres user = we need to create postgres userĀ 

sudo -u postgres psql
then

CREATE USER thisisyou WITH PASSWORD '';
ALTER USER thisisyou WITH SUPERUSER'