LoginSignup
3

More than 3 years have passed since last update.

posted at

楽して遊ぶUbuntu Part1 ~UbuntuとRuby導入~

  • 個人的なメモとして(よく忘れるので)

開発環境

  • 仮想ソフト:Parallels Desktop 13 for mac
  • Ubuntu 16.04
  • Ruby 2.5.1

Ubuntu設置

  • Parallelsの場合、英語版Ubuntu16.04を無料ダウンロードすることで、1. ~ 3.をスキップできる
  1. 下記サイトからUbuntuのISOファイルをダウンロードする
  2. md5sumを確認する
    • Mac:md5 <File Name>
    • Windows:certutil -hashfile <File Path> [Hash Algorithm]
  3. Parallelsを起動し、新規 > DVD/イメージファイルからWindows/その他OSをインストールを選択する
  4. UbuntuのISOファイルを選択する
  5. Linuxユーザー名とパスワードを設定する
  6. Ubuntuの保管ディレクトリを設定する
  7. 構成を設定する
    • メモリを1GB → 4GBに変更
  8. 下記コマンドを実行する

    sudo apt update && sudo apt upgrade -y
    
    • 実行時、下記エラーが発生した場合、こちらを参考にして修正を行う
    E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh > /dev/null; fi'
    E: Sub-process returned an error code
    
  9. Ubuntuを再起動する

Rubyインストール

  • rbenvを使用する
  1. gitをインストールする

    sudo apt install git -y
    
  2. rbenvをインストールする

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    
  3. PATHが通るように.bashrcに設定する

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    
  4. .bashrcに下記を追加する

    eval "$(rbenv init -)"
    
  5. PATHが設定できているか確認する

    • 問題がなければ.bashrcファイルに4., 5.で入力したPATHが記入されている
    cat .bashrc
    
  6. PATHに追記した内容を反映させる(再起動させる)

    source ~/.bashrc
    
  7. コマンドで確認する(2018/05/13現在)

    rbenv -v
    rbenv 1.1.1-30-gc8ba27f
    
  8. ruby-build(rbenvのプラグイン)をインストールする

    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
    
  9. 必要なパッケージをインストールする

    sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev -y
    
  10. rbenvでインストールするRubyのバージョンを確認する

    rbenv install -l
    
  11. Ruby 2.5.1をインストールする

    rbenv install 2.5.1
    
    • インストールに失敗した場合は、エラーメッセージに記載されているパッケージをインストールする

      ERROR: Ruby install aborted due to missing extensions
      Try running `apt-get install -y <Packages that need to be installed>` to fetch missing dependencies.
      
  12. 通常使うバージョンに設定する

    rbenv global 2.5.1
    
  13. Rubyのバージョンを確認する

    ruby -v
    ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
    
  14. (任意)gemのバージョンを更新する

    gem update --system
    
  15. (任意)bundlerを導入する

    gem install bundler
    

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
3