質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

4806閲覧

rails new のバージョン指定について

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

1グッド

0クリップ

投稿2017/03/20 11:20

編集2017/03/21 12:46

###前提・実現したいこと
rails newにてアプリケーションを作成した際に、バージョンを5.0.0.1に指定をしました。
しかし作成されたアプリケーションは、指定したバージョンとは異なり5.0.2となっていました。

原因が不明なので、ご回答お願い致します。

###コンソール(実行結果)

~/workspace $ gem install rails --version 5.0.0.1 Fetching: i18n-0.8.1.gem (100%) Successfully installed i18n-0.8.1 Fetching: thread_safe-0.3.6.gem (100%) Successfully installed thread_safe-0.3.6 Fetching: tzinfo-1.2.2.gem (100%) Successfully installed tzinfo-1.2.2 Fetching: concurrent-ruby-1.0.5.gem (100%) Successfully installed concurrent-ruby-1.0.5 Fetching: activesupport-5.0.0.1.gem (100%) Successfully installed activesupport-5.0.0.1 Fetching: rack-2.0.1.gem (100%) Successfully installed rack-2.0.1 Fetching: rack-test-0.6.3.gem (100%) Successfully installed rack-test-0.6.3 Fetching: mini_portile2-2.1.0.gem (100%) Successfully installed mini_portile2-2.1.0 Fetching: nokogiri-1.7.1.gem (100%) Building native extensions. This could take a while... Successfully installed nokogiri-1.7.1 Fetching: loofah-2.0.3.gem (100%) Successfully installed loofah-2.0.3 Fetching: rails-html-sanitizer-1.0.3.gem (100%) Successfully installed rails-html-sanitizer-1.0.3 Fetching: rails-dom-testing-2.0.2.gem (100%) Successfully installed rails-dom-testing-2.0.2 Fetching: builder-3.2.3.gem (100%) Successfully installed builder-3.2.3 Fetching: erubis-2.7.0.gem (100%) Successfully installed erubis-2.7.0 Fetching: actionview-5.0.0.1.gem (100%) Successfully installed actionview-5.0.0.1 Fetching: actionpack-5.0.0.1.gem (100%) Successfully installed actionpack-5.0.0.1 Fetching: activemodel-5.0.0.1.gem (100%) Successfully installed activemodel-5.0.0.1 Fetching: arel-7.1.4.gem (100%) Successfully installed arel-7.1.4 Fetching: activerecord-5.0.0.1.gem (100%) Successfully installed activerecord-5.0.0.1 Fetching: globalid-0.3.7.gem (100%) Successfully installed globalid-0.3.7 Fetching: activejob-5.0.0.1.gem (100%) Successfully installed activejob-5.0.0.1 Fetching: mime-types-data-3.2016.0521.gem (100%) Successfully installed mime-types-data-3.2016.0521 Fetching: mime-types-3.1.gem (100%) Successfully installed mime-types-3.1 Fetching: mail-2.6.4.gem (100%) Successfully installed mail-2.6.4 Fetching: actionmailer-5.0.0.1.gem (100%) Successfully installed actionmailer-5.0.0.1 Fetching: nio4r-1.2.1.gem (100%) Building native extensions. This could take a while... Successfully installed nio4r-1.2.1 Fetching: websocket-extensions-0.1.2.gem (100%) Successfully installed websocket-extensions-0.1.2 Fetching: websocket-driver-0.6.5.gem (100%) Building native extensions. This could take a while... Successfully installed websocket-driver-0.6.5 Fetching: actioncable-5.0.0.1.gem (100%) Successfully installed actioncable-5.0.0.1 Fetching: thor-0.19.4.gem (100%) Successfully installed thor-0.19.4 Fetching: method_source-0.8.2.gem (100%) Successfully installed method_source-0.8.2 Fetching: railties-5.0.0.1.gem (100%) Successfully installed railties-5.0.0.1 Fetching: bundler-1.14.6.gem (100%) Successfully installed bundler-1.14.6 Fetching: sprockets-3.7.1.gem (100%) Successfully installed sprockets-3.7.1 Fetching: sprockets-rails-3.2.0.gem (100%) Successfully installed sprockets-rails-3.2.0 Fetching: rails-5.0.0.1.gem (100%) Successfully installed rails-5.0.0.1 36 gems installed ~/workspace $ rails --version Rails 5.0.0.1 ~/workspace $ rails _5.0.0.1_ new hello_app create create README.md create Rakefile create config.ru create .gitignore create Gemfile ・ ・省略 ・ create vendor/assets/javascripts create vendor/assets/javascripts/.keep create vendor/assets/stylesheets create vendor/assets/stylesheets/.keep remove config/initializers/cors.rb run 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 version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Resolving dependencies... Installing rake 12.0.0 Using concurrent-ruby 1.0.5 Using i18n 0.8.1 Installing minitest 5.10.1 Using thread_safe 0.3.6 Using builder 3.2.3 Using erubis 2.7.0 Using mini_portile2 2.1.0 Using rack 2.0.1 Installing nio4r 2.0.0 with native extensions Using websocket-extensions 0.1.2 Using mime-types-data 3.2016.0521 Using arel 7.1.4 Using bundler 1.14.6 Installing byebug 9.0.6 with native extensions Installing coffee-script-source 1.12.2 Installing execjs 2.7.0 Using method_source 0.8.2 Using thor 0.19.4 Installing debug_inspector 0.0.2 with native extensions Installing ffi 1.9.18 with native extensions Installing multi_json 1.12.1 Installing rb-fsevent 0.9.8 Installing puma 3.8.2 with native extensions Installing sass 3.4.23 Installing tilt 2.0.7 Installing sqlite3 1.3.13 with native extensions Installing turbolinks-source 5.0.0 Using tzinfo 1.2.2 Using nokogiri 1.7.1 Using rack-test 0.6.3 Using sprockets 3.7.1 Using websocket-driver 0.6.5 Using mime-types 3.1 Installing coffee-script 2.4.1 Installing uglifier 3.1.9 Installing rb-inotify 0.9.8 Installing turbolinks 5.0.1 Installing activesupport 5.0.2 Using loofah 2.0.3 Using mail 2.6.4 Installing listen 3.0.8 Using rails-dom-testing 2.0.2 Using globalid 0.3.7 Installing activemodel 5.0.2 Installing jbuilder 2.6.3 Installing spring 2.0.1 Using rails-html-sanitizer 1.0.3 Installing activejob 5.0.2 Installing activerecord 5.0.2 Installing spring-watcher-listen 2.0.1 Installing actionview 5.0.2 Installing actionpack 5.0.2 Installing actioncable 5.0.2 Installing actionmailer 5.0.2 Installing railties 5.0.2 Using sprockets-rails 3.2.0 Installing coffee-rails 4.2.1 Installing jquery-rails 4.2.2 Installing web-console 3.4.0 Installing rails 5.0.2 Installing sass-rails 5.0.6 Bundle complete! 15 Gemfile dependencies, 62 gems now installed. Use `bundle show [gemname]` to see where a bundled gem is installed. run bundle exec spring binstub --all * bin/rake: spring inserted * bin/rails: spring inserted ~/workspace $ rails --version Rails 5.0.2 ~/workspace/hello_app $ rails --version Rails 5.0.2

###Gemfile

source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console' gem 'listen', '~> 3.0.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

###備考

開発環境はcloud9です。
退会済みユーザー👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

起こっている事:

$ rails 5.0.0.1 new hello_app
を実行すると、 hellp_app フォルダーにファイルが作成されます。(Gemfile も)
そして, bundle install も自動実行されます。その時に rails 5.0.2 が install されてしまいます。
$ rails --version では、そのときに入った 5.0.2 が動作することになります。

$ gem list rails とすると
rails (5.0.2, 5.0.0.1)
のように、複数バージョンがはいっていることが確認できるはずです。

回避方法案:
rails new したときに、 bundle install を自動実行しないようにします。
$ rails 5.0.0.1 new hello_app --skip-bundle

$ cd hello_app して、ファイル一覧を確認すると Gemfile.lock はまだ存在していないはずです。(bundle install が実行されていないから)

Gemfile を編集して、 rails の version を 5.0.0.1 に固定します。
gem 'rails', '= 5.0.0.1'

bundle install で gem の格納先を vender/bundle に指定します。
$ bundle install --path=vendor/bundle

rails の version を確認します。
$ rails --version
Rails 5.0.0.1

$ which rails
./bin/rails

$ bundle exec gem list rails
...
rails (5.0.0.1)
...

rails new でつくった folder 中で, rails や bundle exec でのコマンド実行は、 bin/* のものが優先されたり、Gemfile でインストールされた gem を使うようになったりします。

親フォルダに移動して、gem list すると 5.0.2 などシステム上にある gem が列挙されます。
$ cd ..
$ gem list rails
rails (5.0.2, 5.0.0.1)

参考情報

  • Bundlerを使ったGemパッケージの管理

http://www.rubylife.jp/rails/ini/index2.html

  • Rails 4.1以降のコンソールコマンドは必ず bin/ を付けなきゃいけないの?

http://qiita.com/jnchito/items/c5a0848144203dce6e26

投稿2017/03/25 00:55

katoy

総合スコア22324

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

Gemfileで

ruby

1gem 'rails', '~> 5.0.0', '>= 5.0.0.1'

となっていますが、これは「5.0.0.1以上の5.0.x」を使う、という意味です。他のGemの都合で入れられない場合を除いて、Bundlerはできるだけ新しいGemを入れようとします。

どうしても5.0.0.1に固定したいなら、gem 'rails', '5.0.0.1'と不等号なしで書いて下さい。

投稿2017/03/24 06:46

maisumakun

総合スコア145121

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問