Ruby on Rails: How to setup Postgresql? TLDR
1. gemfile: #
add gem "pg"
remove gem "sqlite"
2. console: #
SCRIPT TO INSTALL LATEST VERSION OF POSTGRESQL
Install Postgresql and create a user:
sudo apt install postgresql libpq-dev
sudo su postgres
createuser --interactive
ubuntu
y
exit
You can fix Connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed
by just starting/restarting postgresql:
sudo service postgresql restart
check version of postgresql
pg_config --version
To create another user with a password:
sudo su postgres
createuser --interactive --pwprompt
username
password
y
exit
Set default password for a postgresql user: in this case we set password myPassword
for user postgres
sudo -u postgres psql
ALTER USER postgres PASSWORD 'myPassword';
\q
Now you can install the gem and run migrations:
bundle
rails db:create db:migrate
rails s
That’s it 🥳 !
Relevant links #
Did you like this article? Did it save you some time?