Home>

I want to install rails.

Installed rails at terminal in mac 10.12.6 environment.
However, if you look at the version with rails -v,
sudo gem install rails is displayed.

http://tomoprog.hatenablog.com/entry/2017/02/03/015936
Repeated sudo gem install rails resulted in the same error again.

I think this is the case,
If i look at ".bash_profile" in the user folder name,

alias brew ="env PATH = ${PATH/\/Users \/username \/\. pyenv \/shims: /} brew"
alias brew ="env PATH = ${PATH/\/Users \/username \/\. pyenv \/shims: /} brew"

Since there were two lines that were the same as

, I edited it as follows.

alias brew ="env PATH = ${PATH/\/Users \/username \/\. pyenv \/shims: /} brew"
export PATH ="$HOME/.rbenv/bin: $PATH"

If i run sudo gem install rails again in this state,
The following error occurred in the future.

ERROR: Could not find a valid gem'rails'(>= 0), here is why:
Unable to download data from https://rubygems.org/-SSL_connect returned = 1 errno = 0 state = SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/latest_specs.4.8.gz)

Unable to identify the cause. .
Please let me know if you know anything.


>Takahashim
thanks for your comment.

>ruby ​​-v What does it display? (I want to know the Ruby version)
This is the result.
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

>What will be displayed when you run which ruby?
This is the result.
/ usr/bin/ruby ​​

-------------

By the way, I do n’t know if it ’s related,
The ruby ​​installation doesn't seem to work,

rbenv global 2.4.1
After hitting
rbenv versions
And hit
system

  • 2.4.1 (set by /Users/username/.ruby-version)
    It becomes.

Just then
ruby -v
But still
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

It remains

. .

  • Answer # 1

    If

    ruby ​​-vgives 2.0.0, it means that the macOS system standard Ruby is used.
    Rails 5.x's corresponding Ruby is "Ruby 2.2.2 or newer", so this Ruby is a bit too old. Therefore, it is necessary to use Ruby installed with rbenv.
    https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions

    If you use rbenv, it is the Ruby version used by Rais. If there is a file called .ruby-version in that directory, the version of Ruby written in that file will be used.
    To change this, runrbenv local 2.4.1. Then, I think that the contents of .ruby-version will be2.4.1.
    You should rungem install railson this.

    By the way, if you are using rbenv, you should be able to execute the gem command without attachingsudo(if you execute it once withsudoYou may not be able to change it later ...) This is because the administrator authority is required to write the gems directory used by the system standard Ruby, but rbenv puts the gems file directly under the user's HOME, so it can be read and written with the user's authority.


    Note

      

    ERROR: Could not find a valid gem'rails'(>= 0), here is why:
      Unable to download data from https://rubygems.org/-SSL_connect returned = 1 errno = 0 state = SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/latest_specs.4.8.gz)

    An error such as

    occurs when the Ruby version is old. In my environment, I tried using gem 2.0.14.1 (macOS standard Ruby) of ruby ​​2.0.0p648. This means that if you get this error withgem install rails, it means that the gem command attached to ruby ​​installed with rbenv is not used, so you need to solve it (There is no need to reinstall rubygems).


      

    ERROR: While executing gem ... (Errno :: EACCES)
      Permission denied @ rb_sysopen-/Users/username/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rails-5.2.0/README.md

    If you get an error like

    , you may have mixed sudo with Permission and not sudo.
    It may be a good idea to uninstall and reinstall the gem.

    Usegem uninstallto uninstall gem.
    First trygem uninstall -a -I -x --force, and if any error occurs,sudo gem uninstall -a -I -x --forceTry to run it. The installed gem should now disappear.
    Then, try installing again withgem install rails.