LoginSignup
4
10

More than 5 years have passed since last update.

Rails を Windows 10で動かす with PostgreSQL

Last updated at Posted at 2017-03-18

モチベーション

友人とウェブサービスを作ろうという話になったので、環境構築の方法をまとめたほうがいいかなと思っやりました。英語なのはただの趣味です。おかしいところがあれば、編集リクエストお待ちしております。

Build the development environment

We decided that we use below:

  • Ruby 2.3.3
  • Rails 5.0.2
  • PostgreSQL 9.6.2

Install Ruby

$ SET PATH=%PATH%;C:\Ruby23-x64\bin
  • Try to execute ruby. Please type below by command prompt:
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]

Get DevKit

https://dl.bintray.com/oneclick/rubyinstaller/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

Extract exe file in any place. e.g. C:\DevKit. And move to the folder which is extracted DevKit files. And then, install DevKit

$ ruby dk.rb init
$ ruby dk.rb install

Install Rails

Next Install rails by rubygems.

$ gem install rails --no-ri --no-rdoc

Confirm if rails was installed correctly.

$ rails -v
Rails 5.0.2

Install PostgreSQL

Get the installer from PostgreSQL web site

https://www.postgresql.org/download/windows/

A "Download the installer" link on this site takes you to download the installer page. Select PostgreSQL 9.6.2 in postgreSQL's versions, and Windows x86-64 in Operating System. And then click DOWNLOAD NOW

The installation settings are basically default other than below:

  • Installation Path : any place which is not including spaces. e.g. C:\pg\PostgreSQL\9.6\bin
  • Password : (any) Please don't forget it. this is necessary when connecting rails app to DB.
  • Port : 5432
  • Advanced Options : English, United States

If you see the wizard of StackBuilder after postgreSQL installation, please cancel. It is not necessary the additional module for now.

After installation, set PATH environment variable

$ SET PATH=%PATH%;C:\pg\PostgreSQL\9.6\bin

Create Data Base

launch psql

$ psql -U postgres
User postgres password:
psql (9.6.2)

postgres=#

create role

postgres=# create role myapp with createdb login password 'password';

create database

postgres=# create database myapp_development owner myapp;

quit

postgres=# \q

Create new your app

Please type in any directory

$ rails new myapp -TB --database=postgresql
$ cd myapp
$ bundle install

Edit config/database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: myapp    # Add this line
  password: password # Add this line
  host: localhost    # Add this line
development:
  <<: *default
  database: myapp_development

Migrate database

$ rake db:migrate

Start Rails

$ rails server --environment=development

Access to http://localhost:3000. You will be able to see the rails default page.

That's all !!

Have fun!!

4
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
10