ruby:ruby_install

Ruby のインストール

$ sudo dnf groupinstall "Development Tools"
$ sudo dnf install fedora-packager
$ rpmdev-setuptree

Rawhide とは Fedora の開発バージョンである🤔
以下の URL より開発バージョンのパッケージソースを取得できる。最新のパッケージ名は随時更新されるので直接確認する😉
https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/development/rawhide/Everything/source/tree/Packages/r/

$ curl -O http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/development/rawhide/Everything/source/tree/Packages/r/ruby-2.6.1-112.fc30.src.rpm
$ rpm -ivh ruby-2.6.1-112.fc30.src.rpm
$ sudo dnf builddep ~/rpmbuild/SPECS/ruby.spec

パッケージに署名をする準備については rpmbuild を参照。

$ rpmbuild --sign -ba ~/rpmbuild/SPECS/ruby.spec
$ createrepo -v ~/rpmbuild/RPMS/
$ sudo dnf install --nogpgcheck --repofrompath=local,/home/tomoyan/rpmbuild/RPMS/ ruby ruby-devel
$ ruby -v
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
$ sudo dnf install ruby
$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
  1. RubyInstaller Downloadsより Ruby Installer for Windows をダウンロードする。
    ※ここでは Windows x64 用の rubyinstaller-2.5.3-1-x64.exe をダウンロード。
  2. ダウンロードしたファイルを実行して、NetBeans IDE をインストールする。

 ※Ruby Installer for Windows はパスを通したり拡張子関連付けを行ってくれるオプションがあるので、手間を掛けずに簡単にRuby環境を整えることができる。

  1. Ruby Version Manager(RVM)をインストールする。
    $ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
  2. RVM のインストール確認を行う。
    $ rvm -v
    
    rvm 1.10.2 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]
  3. Shell環境をリロードする。
    $ source ~/.bash_profile
  4. インストールを行う前に依存関係を調べる。
    $ rvm requirements
    
      Notes for Mac OS X 10.7.2, No Xcode.
    
    For JRuby:  Install the JDK. See http://developer.apple.com/java/download/  # Current Java version "1.6.0_26"
    For IronRuby: Install Mono >= 2.6
    For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'
    
    You can use & download osx-gcc-installer: https://github.com/kennethreitz/osx-gcc-installer
    ** NOTE: Currently, Node.js is having issues building with osx-gcc-installer.
     The only fix is to install Xcode over osx-gcc-installer.
    
    To use an RVM installed Ruby as default, instead of the system ruby:
    
        rvm install 1.8.7 # installs patch 357: closest supported version
        rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
        rvm alias create default 1.8.7
    
    And reopen your terminal windows.
    
    Xcode 4.2:
     * is only supported by ruby 1.9.3+ using command line flag: --with-gcc=clang
     * it breaks gems with native extensions, especially DB drivers.
  5. Xcodeをインストールするために、アップルメニューから[App Store…]をクリックする。
  6. App Store ウィンドウ右上の検索ボックスで「xcode」を検索する。
  7. Xcode開発ツールの[無料]をクリックし[APPをインストール]をクリックする。
  8. Apple IDとパスワードを入力してサインインするとインストーラがインストールされる。
  9. LaunchpadよりInstall Xcodeを実行する。
  10. Homebrewをインストールする。
    $ ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
  11. Homebrew のインストール確認を行う。
    $ brew -v
    0.8.1
  12. RubyGemsを更新する。
    sudo gem update --system
  13. Rakeを更新する。
    $ sudo gem update rake
  14. ruby 1.9.3 をインストールする。
    $ rvm install 1.9.3 --with-gcc=clang
    Fetching yaml-0.1.4.tar.gz to /Users/tomoyan/.rvm/archives
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  460k  100  460k    0     0  98665      0  0:00:04  0:00:04 --:--:--  104k
    Extracting yaml-0.1.4.tar.gz to /Users/tomoyan/.rvm/src
    Configuring yaml in /Users/tomoyan/.rvm/src/yaml-0.1.4.
    Compiling yaml in /Users/tomoyan/.rvm/src/yaml-0.1.4.
    Installing yaml to /Users/tomoyan/.rvm/usr
    Installing Ruby from source to: /Users/tomoyan/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...
    
    ruby-1.9.3-p0 - #fetching 
    ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection...
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 9330k  100 9330k    0     0   790k      0  0:00:11  0:00:11 --:--:-- 1120k
    ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/tomoyan/.rvm/src/ruby-1.9.3-p0
    ruby-1.9.3-p0 - #extracted to /Users/tomoyan/.rvm/src/ruby-1.9.3-p0
    ruby-1.9.3-p0 - #configuring 
    ruby-1.9.3-p0 - #compiling
    ruby-1.9.3-p0 - #installing 
    Retrieving rubygems-1.8.15
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  245k  100  245k    0     0   708k      0 --:--:-- --:--:-- --:--:--  831k
    Extracting rubygems-1.8.15 ...
    Removing old Rubygems files...
    Installing rubygems-1.8.15 for ruby-1.9.3-p0 ...
    Installation of rubygems completed successfully.
    ruby-1.9.3-p0 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
    ruby-1.9.3-p0 - #importing default gemsets (/Users/tomoyan/.rvm/gemsets/)
    Install of ruby-1.9.3-p0 - #complete

 一時的に Ruby 1.9.3 に切り替える。

$ rvm use 1.9.3
Using /Users/tomoyan/.rvm/gems/ruby-1.9.3-p0

 Ruby 1.9.3 をデフォルトにする。

$ rvm use 1.9.3 --default
Using /Users/tomoyan/.rvm/gems/ruby-1.9.3-p0
  1. gemset を生成する。
    $ rvm gemset create RailsEnv
    'RailsEnv' gemset created (/Users/tomoyan/.rvm/gems/ruby-1.9.3-p0@RailsEnv).
  2. gemset を選択する。
    $ rvm gemset use RailsEnv
    Using /Users/tomoyan/.rvm/gems/ruby-1.9.3-p0 with gemset RailsEnv
  3. Rails をインストールする。
    $ sudo gem install rails
    Fetching: i18n-0.6.0.gem (100%)
    Fetching: multi_json-1.0.4.gem (100%)
    Fetching: activesupport-3.2.1.gem (100%)
    〜省略〜
    Installing RDoc documentation for rdoc-3.12...
    Installing RDoc documentation for railties-3.2.1...
    Installing RDoc documentation for rails-3.2.1...
  4. bundler をインストールする。
    $ gem install bundler
    Fetching: bundler-1.0.22.gem (100%)
    Successfully installed bundler-1.0.22
    1 gem installed
    Installing ri documentation for bundler-1.0.22...
    Installing RDoc documentation for bundler-1.0.22...

 プロジェクトのディレクトリで以下のコマンドを実行して、Rubyのバージョンとgemsetが自動選択されるようにする。

$ rvm --rvmrc --create ruby-1.9.3-p0@RailsEnv

コマンドを実行するとプロジェクトのフォルダに以下の内容で .rvmrc が生成される。

#!/usr/bin/env bash

# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory

# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
environment_id="ruby-1.9.3-p0@RailsEnv"

#
# Uncomment the following lines if you want to verify rvm version per project
#
# rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
#   echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
#   return 1
# }
#

#
# Uncomment following line if you want options to be set only for given project.
#
# PROJECT_JRUBY_OPTS=( --1.9 )
#
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
#
#    chmod +x ${rvm_path}/hooks/after_use_jruby_opts
#

#
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
#
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
  && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
  \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"

  if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
  then
    . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
  fi
else
  # If the environment file has not yet been created, use the RVM CLI to select.
  if ! rvm --create  "$environment_id"
  then
    echo "Failed to create RVM environment '${environment_id}'."
    return 1
  fi
fi

#
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
# it be automatically loaded. Uncomment the following and adjust the filename if
# necessary.
#
# filename=".gems"
# if [[ -s "$filename" ]]
# then
#   rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
# fi

# If you use bundler, this might be useful to you:
# if [[info_arrange:s_gemfile]] && ! command -v bundle >/dev/null
# then
#   printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
#   gem install bundler
# fi
# if [[info_arrange:s_gemfile]] && command -v bundle
# then
#   bundle install
# fi

if [[ $- == *i* ]] # check for interactive shells
then
    echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
else 
        echo "Using: $GEM_HOME" # don't use colors in interactive shells
fi
  • ruby/ruby_install.txt
  • 最終更新: 2022/09/12 21:05
  • by ともやん