출처: Ruby on Rails Tutorial v6 (Michael Hartl)
[AWS Cloud9 환경 설정방법]
AWS로그인후 Cloud9 서비스 선택
Create environment 버튼 클릭
Name: rails6a
Platform: Ubuntu server 선택
Cost-saving setting은 선택사항
아래는 Cloud9 IDE에서 서버 셋업 화면 캡처
rails:~/environment $ pwd
/home/ubuntu/environment
rails:~/environment $ ls -al
total 16
drwxr-xr-x 3 ubuntu ubuntu 4096 Apr 29 02:40 .
drwxr-xr-x 13 ubuntu ubuntu 4096 Apr 29 04:57 ..
drwxrwxr-x 3 ubuntu ubuntu 4096 Apr 29 02:41 .c9
-rw-r--r-- 1 ubuntu ubuntu 569 Apr 21 14:56 README.md
rails:~/environment $ echo "gem: --no_document" >> ~/.gemrc
rails:~/environment $ cat ~/.gemrc
gem: --no_document
rails:~/environment $ gem install rails -v 6.0.2.1
Fetching activesupport-6.0.2.1.gem
Fetching actionview-6.0.2.1.gem
rails:~/environment $ source <(curl -sL https://cdn.learnenough.com/yarn_install)
OK
deb https://dl.yarnpkg.com/debian/ stable main
Hit:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 https://dl.yarnpkg.com/debian stable
...
rails:~/environment $ rails -v
Rails 6.0.2.1
rails:~/environment $ source <(curl -sL https://cdn.learnenough.com/yarn_install)
OK
deb https://dl.yarnpkg.com/debian/ stable main
Hit:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 https://dl.yarnpkg.com/de...
...
Installing dev server for live reloading
run yarn add --dev webpack-dev-server from "."
yarn add v1.22.5
[1/4] Resolving packages...
Gemfile 설정값
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '6.0.2.1'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3', '1.4.1'
# Use Puma as the app server
gem 'puma', '3.12.2'
# Use SCSS for stylesheets
gem 'sass-rails', '5.1.0'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '4.0.7'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '5.2.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.9.1'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '1.4.5', require: false
group :development, :test do
gem 'sqlite3', '1.4.1'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '4.0.1'
gem 'listen', '3.1.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', '2.1.0'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '3.28.0'
gem 'selenium-webdriver', '3.142.4'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers', '4.1.2'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
bundle update와 bundle install
rails:~/environment/hello_app (master) $ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Could not find gem 'sassc (= 3.6.1)' in any of the gem sources listed in your Gemfile.
rails:~/environment/hello_app (master) $ bundle update
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Using rake 12.3.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.10
Using minitest 5.14.4
주의! - 'bundle update' 후에 'bundle install'을 실행해야 함
rails server 실행
- 웹서버를 실행하기 전에 로컬 웹서버 접속을 허용한다.
- 작업경로는 '~/environment/hello_app/'
로컬서버 연결 허용을 위한 설정파일: config/environments/development.rb
...
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# 로컬 서버 연결을 허용
config.hosts.clear
end
rails:~/environment/hello_app (master) $ rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.2 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:8080
Use Ctrl-C to stop
접속주소는 http:/localhost:3000
AWS Cloud9 을 사용하는 경우, 로컬 컴퓨터 브라우저로 접속을 시도하면...
"~~ 연결을 거부했습니다."는 메시지가 나오는 경우가 있다.
이 경우에는 위의 그림의 적색 동그라미 부분을 클릭해서 접속하면 된다.
[요약: Cloud9 IDE사용하여 Ruby on Rails 셋업방법]
------------------------------------------------------
주의! 설치전에 ruby 버전 EOL 정보 반드시 확인할 것
- 2021.5.1일 현재 안정 릴리스: ruby 2.7.3 또는 3.0.1
- 보안 유지보수 단계: 루비 2.6.7(곧 EOL 예정!)
rails 5.2.5 또는 최신버전 6.1.3.1
------------------------------------------------------
*시작 전 루비버전 확인: ruby -v
단계1. 레일즈 설치
$ echo "gem: --no-document" >> ~/.gemrc # 도움말 파일 제외
$ gem install rails -v 6.1.3.1 # 설치 명령
$ rails -v # 설치된 버전확인
단계2. yarn 설치 (yarn은 npm같은 js 패키지 관리자. 빠르고 안정적)
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)
$ yarn install --check-files
단계3. hello_app 생성
$ cd ~/environment
$ rails _6.1.3.1_ new hello_app
단계4. bundle 설치
$ cd hello_app/
$ bundle update
$ bundle install
단계5. 웹서버 실행
필수! - 클라우드 환경에서 로컬 웹서버 접근가능하도록 설정
# hello_app/config/environments/development.rb 파일에 아래 1줄 추가
...
config.hosts.clear ##
end
IDE에서 별도 터미널 탭 사용하여 웹서버 실행
$ cd ~/enviroment/hello_app
$ rails server
환경설정 끝.
업데이트 - Gemfile 설정값(2021.05.01일자)
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '6.1.3.1'
gem 'puma', '5.2.2'
gem 'sass-rails', '6.0.0'
gem 'webpacker', '5.2.1'
gem 'turbolinks', '5.2.1'
gem 'jbuilder', '2.10.0'
gem 'bootsnap', '1.7.2', require: false
group :development, :test do
gem 'sqlite3', '1.4.2'
gem 'byebug', '11.1.3', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '4.1.0'
gem 'rack-mini-profiler', '2.3.1'
gem 'listen', '3.4.1'
gem 'spring', '2.1.1'
end
group :test do
gem 'capybara', '3.35.3'
gem 'selenium-webdriver', '3.142.7'
gem 'webdrivers', '4.6.0'
end
group :production do
gem 'pg', '1.2.3'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# Uncomment the following line if you're running Rails
# on a native Windows system:
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]