[Personal memo] Ruby on Rails environment construction (Windows)

Purpose </ b>

I will look back on what I got stuck in when building the environment of Ruby on Rails on Windows as a memorandum for myself. * This method is for Ruby 6.0.0 or earlier.

I used this as a reference. Let's build an environment for Ruby on Rails! (Windows) --Progate Procedure to install Devkit on Windows7-Qiita msys2 and GNU toolchains (gcc, g ++, gfortran, findutils ... How to use different versions of Ruby on Windows (uru) --Qiita

Ruby installation

Downloads - Ruby Installer Bold "[Ruby + Devkit 2.6.6-1 (x64)](https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.6-1/rubyinstaller-devkit-2.6. 6-1-x64.exe) ”RubyInstaller was downloaded and the installation proceeded. However, when installing MSYS2, the error "Installation failed" occurred. WS000417.JPG By the way, the same event occurred even if the FW was dropped. Therefore, I decided to install it individually.

First install Ruby </ b> </ span>

From Downloads-Ruby Installer to [Ruby 2.6.6-1 (x64)](https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6 Download the installer for .6-1 / rubyinstaller-2.6.6-1-x64.exe) and double-click it. If there is no problem, select "I accept the License" WS000510.JPG

With "Add Ruby exexutables to your PATH", "Associate .rb and .rbw files with this Ruby installation", and "Use UTF-8 as default external encoding" checked, click [Install]. WS000511.JPG WS000512.JPG

Uncheck "Run'ridk install' to setup MSYS2 and development toolchain." And click [Finish] WS000513.JPG This completes the Ruby installation.

Just in case, I added "C: \ Ruby26-x64" to the exclusion column of anti-virus software (Windows Defender in my environment). WS000590.JPG

Install Devkit </ span>

Download Archives - Ruby Installer Download the installer for Devkit at the bottom right of the above site. Double-click the installer (7z self-extracting file), select the appropriate folder, and click [Extract]. WS000591.JPG

Execute the following command to generate config.yml

cmd.exe



> cd c:\opt\devkit
> ruby dk.rb init
[INFO] found RubyInstaller v2.6.6 at C:/Ruby26-x64

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

config.yml has been generated. WS000592.JPG

Open config.yml in an editor and specify the Ruby path if it is not specified. WS000548.JPG

Install Devkit Execute the following command.

cmd.exe


> ruby dk.rb install
[INFO] Updating existing gem override for 'C:/Ruby26-x64'
[INFO] Installing 'C:/Ruby26-x64/lib/ruby/site_ruby/devkit.rb'

SQLite 3 installation

SQLite Download Page

Check "Precompiled Binaries for Windows" on the download page of Sqlite3 and check "[sqlite-dll-win64-x64-3330000.zip](https://www.sqlite.org/2020/sqlite-dll-win64-x64" -3330000.zip) "," sqlite-tools-win32-x86-3330000.zip "download. WS000549.JPG Unzip the downloaded folder and copy the files "sqlite3.dll" and "sqlite3.exe" to "C: \ Ruby26-x64 \ bin". (* sqlite3.exe has only 32bit version, but it seems that it also supports 64bit.) WS000550.JPG

If you come to this point and execute the command "gem install rails -v" 5.2.3 "", you can either execute the command of ridk install or I got a message asking me to install MSYS2.

Install MSYS2

From the MSYS2 site [msys2-x86_64-20200903.exe](https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20200903. Download exe). First, set the environment variables from [Control Panel]-[System and Security]-[System]-[Environment Variables (N)].

● System environment variable MSYSTEM: MINGW64

● System environment variables PKG_CONFIG_PATH: / usr / lib / pkgconfig: / usr / share / pkgconfig: / lib / pkgconfig

● Added to the end of the system environment variable Path:

  • C:\msys64\mingw64\bin
  • C:\msys64\usr\local\bin
  • C:\msys64\usr\bin
  • C:\msys64\bin

WS000593.JPG

WS000595.JPG

WS000596.JPG

Below is a screenshot of the part where Path seems unnecessary. WS000562.JPG WS000563.JPG

Double-click the downloaded file to proceed with the installation. The progress of the installation is as follows. Press [Next] to proceed. WS000552.JPG WS000553.JPG WS000554.JPG WS000555.JPG You can check the progress by pressing [Show Details]. WS000518.JPG WS000557.JPG Press [Next] when the installation is complete. WS000558.JPG Press [Next] when the installation is complete. WS000559.JPG Press [Finish]. WS000560.JPG The bash screen of MSYS2 starts, but closes it once. WS000561.JPG

Run MSYS2 bash as an administrator. However, in my environment, there was only [Open file location] in the right-click menu, so I opened the file location once and did [Run as administrator] of "MSYS2 MSYS" from the shortcut group of the start menu. WS000564.JPG WS000565.JPG Execute the following command and check the environment variables.

bash


>echo $MSYSTEM

>echo $PATH

>echo $PKG_CONFIG_PATH

If the environment variables have been set, the display will be as follows. WS000566.JPG

Execute the following command, and when you are asked something, type [y] and press the Enter key.

bash



> pacman -Sy pacman

WS000567.JPG WS000568.JPG WS000569.JPG When you are done, close the MSYS screen once. Run MSYS2 MSYS again as administrator. WS000565.JPG Package database and pacman and core package updates Execute the following command, and when you are asked something, type [y] and press the Enter key.

bash


>pacman -Syu

WS000570.JPG WS000571.JPG WS000572.JPG WS000573.JPG WS000574.JPG When you're done, close the MSYS screen.

Package update Run MSYS2 MSYS again as administrator. Execute the following command.

bash


> pacman -Su

WS000575.JPG

In my environment, I got a message saying "I have nothing to do". When you're done, close the MSYS screen.

Start the Windows command prompt and execute the following command.

cmd.exe


> where bash

> where ls

WS000576.JPG In my environment, "C: \ Windows \ System32 \ bash.exe" was displayed probably because of the effect of installing wsl, but it seems that there is no particular effect.

Install Ruby version control uru for Windows

I think that there will be situations where different versions of Ruby are used properly depending on the environment where Ruby on Rails is used, so I installed uru.

From jonforums / uru / wiki / Downloads — Bitbucket uru-0.8.5-windows-x86 /uru/downloads/uru-0.8.5-windows-x86.7z) Download the file

  • It is a 32-bit version, but it seems that it also supports 64-bit. WS000577.JPG Unzip the downloaded 7z and move it to a suitable folder. I moved under C: \ opt. Pass the moved uru folder through the path. WS000578.JPG

Execute the following command at the command prompt.

cmd.exe


>uru_rt admin install
---> Installing uru into C:\opt\uru-0.8.5-windows-x86

"Uru.bat" and "uru.ps1" are generated. WS000579.JPG

Register the path to Ruby in uru.

cmd.exe



> uru admin add C:\Ruby26-x64\bin
---> Registered ruby at `C:\Ruby26-x64\bin` as `266p146`

Check if it is registered in uru.

cmd.exe



> uru ls
    266p146     : ruby 2.6.6p146 (2020-03-31 revision 67876) [x64-mingw32]

Run ridk install

Then run ridk install.

cmd.exe



> ridk install

WS000580.JPG Type [1] and press Enter. WS000581.JPG It seems that it has already been installed.

Type [2] and press Enter. WS000582.JPG It seems to be up to date. There are no more errors.

Type [3] and press Enter. WS000583.JPG Installation is in progress.

WS000584.JPG "Succeeded" is displayed and it seems that it ended normally. Press Enter.

Install Ruby on Rails

Start the command prompt again and execute the following command.

cmd.exe


> gem install rails -v "5.2.3"

WS000597.JPG

Since the message "installed" was confirmed, it seems that the installation of the gem was completed.

Let's check the version of rails.

cmd.exe


> rails -v
Rails 5.2.3

The installation of Rails was completed normally.

Creating a Rails sample app

Let's make a sample app.

Execute the following command.

cmd.exe


> rails new sample_app -G

sample_app is the app name, so you can add it freely, The -G option is on if you don't have Git installed.

The message "Bundle complete!" Is displayed, and it seems that it ended normally. There is a message in NOTICE that chromedriver-helper is no longer supported, but I would like to take this opportunity again. WS000598.JPG

You have a folder named sample_app, which means you have created your Rails application. WS000600.JPG WS000599.JPG

Launch Rails

cmd.exe


> cd sample_app

Navigate to the sample_app folder.

Execute the following command.

cmd.exe


> rails s

cmd.exe


rails s
=> Booting Puma
=> Rails 5.2.4.4 application starting in development
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.12.6 (ruby 2.6.6-p146), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

You can see that the server is running at "localhost: 3000". WS000601.JPG

Try accessing "localhost: 3000" with your browser. WS000602.JPG

I was able to confirm that the Rails server started.

You can stop the server by pressing [Ctrl] + [C].

Done

Recommended Posts