====== Ruby のインストール ====== ===== 最新の Ruby のインストール ===== ==== rpmbuild 環境を整える ==== $ sudo dnf groupinstall "Development Tools" $ sudo dnf install fedora-packager ==== rpmbuild を行うためのディレクトリ構造を作成 ==== $ rpmdev-setuptree ==== ruby の srpm をダウンロード ==== [[https://docs.fedoraproject.org/en-US/releases/rawhide/|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 ==== srpm のインストール ==== $ rpm -ivh ruby-2.6.1-112.fc30.src.rpm ==== ビルドに必要なパッケージのインストール ==== $ sudo dnf builddep ~/rpmbuild/SPECS/ruby.spec ==== RPM パッケージのビルドと署名 ==== パッケージに署名をする準備については [[linux:fedora:rpmbuild|rpmbuild]] を参照。 $ rpmbuild --sign -ba ~/rpmbuild/SPECS/ruby.spec ==== RPM パッケージのインストール ==== $ createrepo -v ~/rpmbuild/RPMS/ $ sudo dnf install --nogpgcheck --repofrompath=local,/home/tomoyan/rpmbuild/RPMS/ ruby ruby-devel ==== ruby のバージョン確認 ==== $ ruby -v ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux] ===== パッケージのインストール ===== ==== Fedora の場合 ==== $ sudo dnf install ruby $ ruby -v ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux] ==== Windows の場合 ==== - [[http://rubyinstaller.org/downloads/|RubyInstaller Downloads]]より Ruby Installer for Windows をダウンロードする。\\ ※ここでは Windows x64 用の rubyinstaller-2.5.3-1-x64.exe をダウンロード。 - ダウンロードしたファイルを実行して、NetBeans IDE をインストールする。  ※Ruby Installer for Windows はパスを通したり拡張子関連付けを行ってくれるオプションがあるので、手間を掛けずに簡単にRuby環境を整えることができる。 ==== Mac OS X Lion の場合 ==== - Ruby Version Manager(RVM)をインストールする。 $ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) - RVM のインストール確認を行う。 $ rvm -v rvm 1.10.2 by Wayne E. Seguin , Michal Papis [https://rvm.beginrescueend.com/] - Shell環境をリロードする。 $ source ~/.bash_profile - インストールを行う前に依存関係を調べる。 $ 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. - Xcodeをインストールするために、アップルメニューから[App Store...]をクリックする。 - App Store ウィンドウ右上の検索ボックスで「xcode」を検索する。 - Xcode開発ツールの[無料]をクリックし[APPをインストール]をクリックする。 - Apple IDとパスワードを入力してサインインするとインストーラがインストールされる。 - LaunchpadよりInstall Xcodeを実行する。 - Homebrewをインストールする。 $ ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)" - Homebrew のインストール確認を行う。 $ brew -v 0.8.1 - RubyGemsを更新する。 sudo gem update --system - Rakeを更新する。 $ sudo gem update rake - 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 のバージョンを切り替える =====  一時的に 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 ===== gemset の生成 ===== - gemset を生成する。 $ rvm gemset create RailsEnv 'RailsEnv' gemset created (/Users/tomoyan/.rvm/gems/ruby-1.9.3-p0@RailsEnv). - gemset を選択する。 $ rvm gemset use RailsEnv Using /Users/tomoyan/.rvm/gems/ruby-1.9.3-p0 with gemset RailsEnv - 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... - 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 [@], 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 ===== 参考文献 ===== [[https://rvm.io/rvm/install|RVM: Ruby Version Manager - Installing RVM]]\\ [[http://www.oiax.jp/rails/zakkan/rails_3_1_installation_on_macosx.html|Ruby on Rails 3.1 を Mac OS X にインストールする手順をかなり丁寧に説明してみました - Rails 雑感 - Ruby on Rails with OIAX]]\\