Build an environment where you can try Rails Girls or el-training on Clound9

Introduction

Let's study Ruby (https://github.com/everyleaf/el-training) such as Rails Gilrs and [el-training] which is a curriculum for new employee education of Manyo. This is an environment construction guide for those who do not have a Mac or have poor PC specifications.

: bangbang: Regarding Rails Girls, please note that the target is not for participation, but for those who want to try coaching but are not good at building an environment (Is there such a person?): Bow:

What does RailsGirls look like? When I pulled out a windows machine that I don't normally use and built it on WSL, it took an hour to check the operation of rails (PC is powerless, probably HDD instead of SSD) Is a major cause), so I built it on Cloud9.

If you search on the net, you will find many things with the same content, but since it was different from the environment you wanted, it also serves as a memo. In addition, I tried to summarize it carefully so that it will be helpful even if time passes from the publication of this article.

Goal of this construction article

--Achievements in Rails Girls --Equivalent to the completion of "Installation Guide" --The difference is the installation of Postgresql (essentially unnecessary for rails girls) --Achievement point in el-training -"[Step 1: Build a Rails development environment](https://github.com/everyleaf/el-training/blob/master/docs/el-training.md#%E3%82%B9%E3%" 83% 86% E3% 83% 83% E3% 83% 971-rails% E3% 81% AE% E9% 96% 8B% E7% 99% BA% E7% 92% B0% E5% A2% 83% E3% 82% 92% E6% A7% 8B% E7% AF% 89% E3% 81% 97% E3% 82% 88% E3% 81% 86) ”equivalent to completion

conditions

--It is a prerequisite that AWS account creation and IAM settings have been completed in advance. --I tried it from May 15, 2020 to May 16, 2020. --ruby / rails environment is as follows - ruby2.6.6 --Rails girls are the latest (still 2.7 series), so please read - rails6.0.3 --Use postgresql (replace mysql in Cloud9 environment as it is already installed) --Use webpacker --Cloud9 settings --Select ʻUbuntu Server 18.04 LTS` on Platform

Construction procedure

Until Cloud9 launch and terminal launch

Please start it first. image.png

Open New Terminal.

image.png

When opened, the terminal will start with the ~ / environment directory as the current directory. Apparently, in Cloud9, it seems to be a good idea to put project files etc. under this directory.

image.png

Change time zone

The date is not in Japan time (UTC).

Confirmation of date


y-amadatsu:~/environment $ date
Sat May 16 02:29:10 UTC 2020

Let's change the time zone first.

Check the time zone


y-amadatsu:~/environment $ timedatectl list-timezones | grep -i tokyo
Asia/Tokyo

If you check the time zone to set, it looks like ʻAsia / Tokyo`.

Time zone setting


y-amadatsu:~/environment $ sudo timedatectl set-timezone Asia/Tokyo
y-amadatsu:~/environment $ date
Sat May 16 11:33:46 JST 2020

I was able to confirm that it was changed to Japan time with the date command.

Until Ruby installation

Check the Ruby version. It's a bit old, so get ready to install the new version.

Check the installation status of ruby


y-amadatsu:~/environment $ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
y-amadatsu:~/environment $ which ruby
/home/ubuntu/.rvm/rubies/ruby-2.6.3/bin/ruby

By default, rvm was installed, but since I usually use rbenv, I will reinstall it.

First of all, rvm, goodbye: raised_hand:

Uninstall rvm


y-amadatsu:~/environment $ rvm implode
Are you SURE you wish for rvm to implode?
This will recursively remove /home/ubuntu/.rvm and other rvm traces?
(anything other than 'yes' will cancel) > yes
Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
Removing rvm wrappers in /home/ubuntu/.rvm/bin
Hai! Removing /home/ubuntu/.rvm
/home/ubuntu/.rvm has been removed.

Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
Also make sure to remove `rvm` group if this was a system installation.
Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).

At the end, you are instructed to delete unnecessary files etc., but in my environment started as environment [^ aws-environment] for the first time, it seems inconvenient to just run rails, so I will proceed as it is. If you later encounter inconveniences such as the ruby command not being found or the version of ruby being executed is different, let's review the above settings.

[^ aws-environment]: Cloud9 operating environment (environment).

Now install rbenv. Proceed while observing the installation procedure of Honke site.

Install rbenv


y-amadatsu:~/environment $ sudo apt-get update
y-amadatsu:~/environment $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
y-amadatsu:~/environment $ cd ~/.rbenv && src/configure && make -C src
make: Entering directory '/home/ubuntu/.rbenv/src'
gcc -fPIC     -c -o realpath.o realpath.c
gcc -shared -Wl,-soname,../libexec/rbenv-realpath.dylib  -o ../libexec/rbenv-realpath.dylib realpath.o 
make: Leaving directory '/home/ubuntu/.rbenv/src'

This time I tried it according to the installation procedure, but from now on I think it is better to replace sudo apt-get update with sudo apt update and get used to it [^ apt-get].

[^ apt-get]: See https://linuxfan.info/package-management-ubuntu. Although apt has been recommended and it stands out quite a bit, there are many descriptions that are not up-to-date on the net like this.

Also, I tried cd ~ / .rbenv && src / configure && make -C src for Bash. I think it will speed up because it is compiled, but it is usually unnecessary [^ rbenv-compile]. It changed to the current directory ~ / .rbenv, but I will continue without worrying about it ...

[^ rbenv-compile]: I think there is no problem because it is fast enough as it is. Rather, I think I'll need to compile it again when I update rbenv itself in the future, but I think I'll probably forget it at that time: angel:

rbenv settings(1)


y-amadatsu:~/.rbenv (master) $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
y-amadatsu:~/.rbenv (master) $ ~/.rbenv/bin/rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

Add it to .bash_profile as instructed.

rbenv settings(2)


y-amadatsu:~/.rbenv (master) $ echo eval "$(rbenv init -)" >> ~/.bash_profile

Close and reopen the terminal as instructed [^ source] Continue. [^ source]: If you search on the net, you will find many explanations for the procedure to execute source ~ / .bash_profile. It's not a mistake, but if you follow the installation instructions (also called primary information) of the software provider, the probability of encountering unknown problems will decrease, so it is recommended that you follow the instructions honestly until you get used to it. Also, I wanted to omit the explanation of directory movement here.

It's a diagnostic program like brew docker.

rbenv settings(3)


y-amadatsu:~/environment $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /home/ubuntu/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: not found
Unless you plan to add Ruby versions manually, you should install ruby-build.
Please refer to https://github.com/rbenv/ruby-build#installation

Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/home/ubuntu/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

Naturally because ruby-build is not included

Checking `rbenv install' support: not found

However, the point that seems to be a little confusing because the sample is shown in the already installed state in the installation procedure of rbenv. However, let's proceed while looking at https://github.com/rbenv/ruby-build#installation as instructed.

This time, we will proceed with the installation as a plug-in of rbenv that seems to be common.

rbenv settings(4)


y-amadatsu:~/environment $ mkdir -p "$(rbenv root)"/plugins
y-amadatsu:~/environment $ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Cloning into '/home/ubuntu/.rbenv/plugins/ruby-build'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10844 (delta 1), reused 3 (delta 0), pack-reused 10835
Receiving objects: 100% (10844/10844), 2.28 MiB | 16.79 MiB/s, done.
Resolving deltas: 100% (7158/7158), done.
y-amadatsu:~/environment $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /home/ubuntu/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /home/ubuntu/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20200401-11-g12af1c3)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/home/ubuntu/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

This is fine. Now install ruby. This time, I installed 2.6.6, which is the latest version of ruby2.6 series. If EC2 is t2.micro, it will take some time: coffee: It took about 10 minutes for me ... maybe (memory is flying: angel :)

installation of ruby


y-amadatsu:~/environment $ rbenv install 2.6.6
Downloading ruby-2.6.6.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.6.tar.bz2
Installing ruby-2.6.6...
Installed ruby-2.6.6 to /home/ubuntu/.rbenv/versions/2.6.6

y-amadatsu:~/environment $ rbenv global 2.6.6
y-amadatsu:~/environment $ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

Alright, the installation is complete!

Installation of required packages and support for unnecessary packages (mysql)

This time we will run rails6, so install the required packages.

As a preliminary preparation, enable yarn to be installed via apt. Refer to Official Site and first register the public key for Debian package repository & set apt before installing.

Registration of yarn repository


y-amadatsu:~/environment $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
OK
y-amadatsu:~/environment $ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main

Be sure to do sudo apt update when you add a repository.

Update apt package list


y-amadatsu:~/environment $ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Get:2 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]                                               
Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease                                             
Get:4 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                           
Get:5 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]                         
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]          
Get:7 https://dl.yarnpkg.com/debian stable/main amd64 Packages [9953 B]
Get:8 https://dl.yarnpkg.com/debian stable/main all Packages [9953 B]    
Fetched 289 kB in 1s (499 kB/s)                    
Reading package lists... Done
Building dependency tree       
Reading state information... Done
30 packages can be upgraded. Run 'apt list --upgradable' to see them.

When I imported the latest package list, it seems that there are many packages that can be updated, so I will update it at this timing.

Applying update packages(upgrade)


y-amadatsu:~/environment $ sudo apt upgrade -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
...abridgement...
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.
Setting up mysql-server (5.7.30-0ubuntu0.18.04.1) ...
Processing triggers for initramfs-tools (0.130ubuntu3.9) ...
update-initramfs: Generating /boot/initrd.img-5.3.0-1017-aws
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.40) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
Processing triggers for ureadahead (0.100.0-21) ...

The update is complete ... and I noticed in the log of: point_up: that mysql seems to be already there ...

Check the mysql process


y-amadatsu:~/environment $ ps aux | grep [m]ysql
mysql    27099  0.1 17.7 1161948 178088 ?      Sl   12:36   0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

After all, it was included. ~~ For religious reasons ~~ This time it is unnecessary, so I will deal with it first. First, stop the service and then disable the package service.

After stopping the service ...

Stop mysql


y-amadatsu:~/environment $ sudo systemctl stop mysql

Make sure it's not working ...

Stop mysql(Verification)


y-amadatsu:~/environment $ sudo systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2020-05-15 12:47:38 UTC; 11s ago
 Main PID: 27099 (code=exited, status=0/SUCCESS)

May 15 12:36:21 ip-10-10-10-180 systemd[1]: Starting MySQL Community Server...
May 15 12:36:22 ip-10-10-10-180 systemd[1]: Started MySQL Community Server.
May 15 12:47:36 ip-10-10-10-180 systemd[1]: Stopping MySQL Community Server...
May 15 12:47:38 ip-10-10-10-180 systemd[1]: Stopped MySQL Community Server.
y-amadatsu:~/environment $ ps aux | grep [m]ysql

Disable the service (turn off the automatic start setting at startup).

Disable mysql service


y-amadatsu:~/environment $ sudo systemctl disable mysql.service
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable mysql
y-amadatsu:~/environment $ sudo systemctl list-unit-files  mysql.service                                                                                                             
UNIT FILE     STATE   
mysql.service disabled

1 unit files listed.

Now install the required packages.

Installation of services required for rails6


y-amadatsu:~/environment $ sudo apt install postgresql libpq-dev redis yarn -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
...abridgement...
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up libsensors4:amd64 (1:3.4.0-4) ...
Setting up postgresql-client-10 (10.12-0ubuntu0.18.04.1) ...
update-alternatives: using /usr/share/postgresql/10/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up redis-tools (5:4.0.9-1ubuntu0.2) ...
Setting up libpq-dev (10.12-0ubuntu0.18.04.1) ...
Setting up sysstat (11.6.1-1ubuntu0.1) ...

Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Setting up postgresql-10 (10.12-0ubuntu0.18.04.1) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start

Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (10+190ubuntu0.1) ...
Setting up redis-server (5:4.0.9-1ubuntu0.2) ...
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.service.
Setting up redis (5:4.0.9-1ubuntu0.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.40) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...

postgres confirms that the postgres user has been created correctly. Also, there is a description such as Creating new PostgreSQL cluster 10 / main .... Does postgres now cluster by default? Thinking:

We will check the operation of postgres later, so let's check if everything else is installed correctly.

Confirmation of installation


y-amadatsu:~/environment $ redis-cli --version
redis-cli 4.0.9
y-amadatsu:~/environment $ redis-server --version
Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=9435c3c2879311f3
y-amadatsu:~/environment $ yarn --version
1.22.4

Redis has 4 systems for both client and server. With sidekiq6, 4 or more is required, so this is safe: relaxed:

Also, postgres and redis will operate as a server, so make sure they are enabled as services.

Confirmation of redis


y-amadatsu:~/environment $ sudo systemctl list-unit-files redis*.service
UNIT FILE             STATE   
redis-server.service  enabled 
[email protected] disabled
redis.service         enabled 

3 unit files listed.

Checking PostgreSQL


y-amadatsu:~/environment $ sudo systemctl list-unit-files postgres*.service
UNIT FILE           STATE   
postgresql.service  enabled 
[email protected] indirect

2 unit files listed.

Sounds like no problem!

Let's start postgres and redis. Check the startup status.

Confirmation of redis


y-amadatsu:~/environment $ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-05-16 01:34:28 UTC; 32min ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
 Main PID: 962 (redis-server)
    Tasks: 4 (limit: 1121)
   CGroup: /system.slice/redis-server.service
           └─962 /usr/bin/redis-server 127.0.0.1:6379

May 16 01:34:27 ip-10-10-10-180 systemd[1]: Starting Advanced key-value store...
May 16 01:34:28 ip-10-10-10-180 systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
May 16 01:34:28 ip-10-10-10-180 systemd[1]: Started Advanced key-value store.

Check postgres


y-amadatsu:~/environment $ sudo systemctl status postgresql.service
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Sat 2020-05-16 01:34:31 UTC; 33min ago
 Main PID: 1386 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 1121)
   CGroup: /system.slice/postgresql.service

May 16 01:34:31 ip-10-10-10-180 systemd[1]: Starting PostgreSQL RDBMS...
May 16 01:34:31 ip-10-10-10-180 systemd[1]: Started PostgreSQL RDBMS.

: bangbang: By the way, regarding the above log, Cloud9 was restarted before and after the confirmation (I confirmed it the day after the installation). Probably neither is running, so let's start it in that case.

Start each service


y-amadatsu:~/environment $ sudo systemctl start redis-server.service
y-amadatsu:~/environment $ sudo systemctl start postgresql.service

It's perfect if you check that it's working properly with the sudo systemctl status ... command!

For postgresql, see the log at the time of installation.

Success. You can now start the database server using:

/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start

However, in the Ubuntu environment, it is more convenient to start / stop via systemctl, so I used this.

All the necessary packages (for the time being [^ package-install]) are now available.

[^ package-install]: If native compilation runs during bundle install of Gemfile, you may need to install the library separately.

Try running rails 6 in a test

Let's check the operation while making a sample rails6 application with reference to railsgarls. Since it is an operation check, detailed explanation is omitted: relieved:

** Rails installation **

Rails installation


y-amadatsu:~/environment $ gem install rails --no-document -v "6.0.3"

** Creating a sample rails app **

Create rails app


y-amadatsu:~/environment $ rails new sample

By the way, rails new sample took about 5 minutes in my environment.

** Operation check **

From creating rails application to starting server


y-amadatsu:~/environment $ cd sample/
y-amadatsu:~/environment/sample (master) $ rails g scaffold book
y-amadatsu:~/environment/sample (master) $ rails db:migrate
y-amadatsu:~/environment/sample (master) $ rails server
=> Booting Puma
=> Rails 6.0.3 application starting in development 
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.3 (ruby 2.6.6-p146), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:8080
* Listening on tcp://[::1]:8080
Use Ctrl-C to stop

Let's check it with a browser. Click Preview Running Application from Preview in the top menu.

image.png

When you click it, the following error screen will be displayed (partially filled in)

rails.png

This is an error displayed by Rails 6's new security mechanism. See below for details.

Try new features of Rails6 78 (Guard DNS rebiding attacks)

Copy config.hosts <<" xxxxxxxxxxxxxx.vfs.cloud9.us-east-1.amazonaws.com " displayed on the error screen and put it in /sample/config/environments/development.rb as follows Please add to and save.

image.png

Stop the currently running server with Ctrl-C.

Rails server down


y-amadatsu:~/environment/sample (master) $ rails server                                 
=> Booting Puma
=> Rails 6.0.3 application starting in development 
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.3 (ruby 2.6.6-p146), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:8080
* Listening on tcp://[::1]:8080
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2020-05-16 17:31:18 +0900 ===
- Goodbye!
Exiting

Then start it again with rails server and double check the preview. In addition, I can not connect with the browser on Cloud9 for some reason ... It seems that no one can solve this even if I try to google. It's definitely a network setting ...: frowning2:

So, on the right side of the URL of the screen that is not connected, there is a "window button that overlaps with the arrow" (mouseover displays "Pop Out Into New Window"), so click it. The button on the right end of the image below.

image.png

Then you can see it in the tab of your browser.

image.png

This completes the installation of rails girls!

Try connecting to postgresql below

At the moment, DB is sqlite, so replace it with postgresql.

First, replace the database.yml file with the following contents [^ database.yml]

[^ database.yml]: Originally it is safer to modify based on database.yml which is the result of rails new appname --database = postgresql in the same rails version.

/config/database.yml


default: &default
  adapter: postgresql
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: postgres
  password: postgres
  host: localhost
  timeout: 5000

development:
  <<: *default
  database: sample_development

test:
  <<: *default
  database: sample_test

production:
  <<: *default
  database: sample_production

The Gemfile should find the line sqlite3, comment it out, and add gem'pg'.

Gemfile


#gem 'sqlite3', '~> 1.4'
gem 'pg'

I modified the Gemfile, so let's do bundle install again [^ bundle-install].

[^ bundle-install]: This is also the case with bundle update. Personally, I use bundle update to upgrade only individual packages.

Install the required packages for rails


y-amadatsu:~/environment/sample (master) $ bundle install

Since this is a development environment, the DB user will leave postgres and set the password easily.

Set password for postgres user


y-amadatsu:~/environment/sample (master) $ sudo -u postgres psql                                                 
psql (10.12 (Ubuntu 10.12-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# alter role postgres with password 'postgres';
ALTER ROLE
postgres=# \q
y-amadatsu:~/environ

Press \ q to return to the console.

In addition, other sites say that it is necessary to modify pg_hba.conf, but with the PostgreSQL 10 series installed this time, the minimum settings were made at the time of installation, so skip it. Below is an excerpt of the installation log.

Creating new PostgreSQL cluster 10/main ... /usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5 The files belonging to this database system will be owned by user "postgres". This user must also own the server process.

This should be fine for your DB settings [^ postgres-user]. I will go at once.

[^ postgres-user]: The postgres user created during installation is a so-called superuser who can do anything, so this usage is NG except for local development. Please create a user for the app separately.

From DB creation to startup confirmation


y-amadatsu:~/environment/sample (master) $ rake db:create
y-amadatsu:~/environment/sample (master) $ rake db:migrate
y-amadatsu:~/environment/sample (master) $ rails server

It's a simple screen, but I've confirmed that / books can also be listed properly.

image.png

Thank you for your hard work!

Recommended Posts

Build an environment where you can try Rails Girls or el-training on Clound9
[Ruby on Rails] Let's build an environment on mac
Build an environment where pip3 can be used with CentOS7 + Python3
Build a development environment where Ruby on Rails breakpoints work on Windows
Build an environment with Docker on AWS
Build an Ultra96v2 development environment on Docker 1
Try to build Java8 environment on Amazon Linux2
Build a Laravel environment on an AWS instance
[Rails] How to build an environment with Docker
Build a Ruby on Rails development environment on AWS Cloud9
[For beginners] Build the environment for Ruby on Rails Tutorial 4th Edition (Rails 5.1) in less than an hour!