New MDGC Virtual Environment Install Tutorial
窓口システムの仮想環境を作成
===
* [name=千神,Shimohashi]
###### tags: `Tutorial`
2023/05/16
[sss](https://docs.google.com/spreadsheets/d/1GMYKVBxRlMv6oNVNzpXYoLUSyT8ZnLEjGcRbn0b4KsA/edit#gid=788239997)
## First need to create Virtual environment
#### 1. vagrant virtual environment install
```
vagrant init oraclelinux/8 https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json
```
:::success
You can check all orcle Linux [version](https://yum.oracle.com/boxes/)
:::
#### 2. vagrant up & Access in
```
vagrant up
vagrant ssh
```
#### 3. Edit SSH file with login location
```
sudo vi ~/.bashrc
Type "I" and new add line with
cd /vagrant/mdgc
Then :wq to save it
reload bashrc
source ~/.bashrc or . ~/.bashrc
```
## Install Ruby's 3 way (yum, rbenv, rvm)
#### 1. I recommend to use rbenv to install ruby
First Need to install rbenv's package
```
sudo dnf install git wget gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
```


type y to install 32 package (Install 39 package)


Use wget to install rbenv & ruby-build
```
(Don's use)wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
(Reference https://github.com/rbenv/rbenv-installer)
wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer -O- | bash
```

<!-- Note that this installer does NOT edit your shell configuration files:
```
1. Run `~/.rbenv/bin/rbenv init' to view instructions on how to configure rbenv for your shell.
2. Launch a new terminal window after editing shell configuration files.
3. (Optional) Run the doctor command to verify the installation:
wget -q "https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor" -O- | bash
``` -->
Then add environment to add this path
```
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
(Don't Use)echo 'eval "$(rbenv init -)"' >> ~/.bashrc
echo 'eval "$(rbenv init - bash)"'
source ~/.bashrc
```
check rbenv is installed or not
```
wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor -O- | bash
```

Check How rbenv's ruby had been install
```
rbenv -L
```
## Install Ruby 2.6.2 and RoR 5.1.7 and bundler 2.0.2
#### 1. Use rbenv to install ruby 2.6.2
```
rbenv install 2.6.2
```

#### 2. Change 2.6.2 to default setting
```
rbenv global 2.6.2
```

###### Q1.
```
If ruby -v can't not reload by linux 8, Need to relauch vagrant
```
#### 3. Install bundler 2.0.2
```
gem install bundler -v 2.0.2
```

#### 4. Install rails 5.1.7
```
gem install rails -v 5.1.7
```

#### 5. Then install all gems
```
bundle install
```
## Install PostgreSQL & Node.js
MUST Javascript Node.js & postgress sql install
#### 1. Upgrade System package:
```
sudo dnf update
```
#### 2. Install PostgreSQL:
```
sudo dnf install postgresql-server
```
#### 3. init PostgreSQL:
```
sudo postgresql-setup --initdb
```
#### 4. Start PostgreSQL:
```
sudo systemctl start postgresql
```
#### 5. IF u want to start always by power on use this command:
```
sudo systemctl enable postgresql
```
#### 6. Check PostgreSQL status:
```
sudo systemctl status postgresql
```
#### 7. Setup /var/lib/pgsql/data/pg_hba.conf
```
vi /var/lib/pgsql/data/pg_hba.conf
host all all 127.0.0.1/32 ident
↓変更する
host all all 127.0.0.1/32 trust
New add it
host all all 0.0.0.0/0 trust
host all all 0.0.0.0/0 trust
```
#### 8. Setup the port local to all
```
vi /var/lib/pgsql/data/postgresql.conf
#listen_addresses = 'localhost'
↓変更する
listen_addresses = '*'
#port = 5432
↓変更する
port = 5432
```
Restrat postgreSQL
```
sudo systemctl stop postgresql
sudo systemctl start postgresql.service
or
sudo systemctl restart postgresql
```
#### 1. Install Node.js
Install Node.js Storge package
```
sudo dnf install -y gcc-c++ make
```
Insatall Node.js
```
sudo dnf install nodejs
```
Check Node.js version
```
node -v
```
#### 2. Edit the puma file
compire puma port 3600 -> 3000
compire puma file deezen to false
#### 3. Compire VagrantFile
```
config.vm.network "forwarded_port", guest: 3000, host: 5000
config.vm.network "forwarded_port", guest: 5432, host: 5433
config.vm.synced_folder ".", "/vagrant", disabled: true # デフォルトの共有を行わない
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
```
#### 4. Improt SQL Data
## Error Message
#### Error 1 nokogiri version is low
```
ERROR: Error installing rails:
The last version of nokogiri (>= 1.6) to support your Ruby & RubyGems was 1.13.10. Try installing it with `gem install nokogiri -v 1.13.10` and then running the current command again
nokogiri requires Ruby version >= 2.7, < 3.3.dev. The current ruby version is 2.6.2.47.
```
Result
```
gem install nokogiri -v 1.13.10
```
#### Error 2 pg_config and libpq file can't found
```
gem install pg -v '1.5.3' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/vagrant/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/pg-1.5.3/ext
/home/vagrant/.rbenv/versions/2.6.2/bin/ruby -I /home/vagrant/.rbenv/versions/2.6.2/lib/ruby/2.6.0 -r ./siteconf20230517-20691-1xrmyie.rb extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... no
checking for libpq per pkg-config... no
Using libpq from
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*****************************************************************************
```
Result
```
sudo yum install postgresql-devel
```