LoginSignup
2
4

More than 5 years have passed since last update.

Bash on Ubuntu on Windows に rbenv と nvm をインストールする

Last updated at Posted at 2016-09-11

Bash on Ubuntu on Windows をいじっていたのですが、複数台の Windows に同じ設定をするのが面倒になってきたので定番アクションを Ansible スクリプトにまとめることにしました。

自分用手順メモとして。

Bash on Ubuntu on Windows 向けと書いていますが Debian/Ubuntu なら動作します。

準備

Bash on Ubuntu on Windows の初期状態からの手順を想定していますが、Ansible が動作する環境を作るところまでは準備します。

apt-get update
apt-get install libssl-dev libffi-dev python-dev python-pip
pip install -U pip
pip install -U ansible

Ansible スクリプト

apt source を国内ミラーに変更する

archive.ubuntu.com からだと遅いので国内ミラーに変更します。

locate の変更はお好みで。

sudo が必要です、sudo 時にパスワードが必要な環境であるときは
ansible-playbook -K ansi_setup.yml-K をつけて実行します。

ansi_setup.yml
- hosts: localhost
  become: yes
  tasks:
    - name: apt source
      replace: dest='/etc/apt/sources.list' replace='/ftp.jaist.ac.jp/pub/Linux/ubuntu' regexp='/archive.ubuntu.com/ubuntu'
    - name: locale to en
      replace: dest='/etc/default/locale' regexp='ja_JP' replace='en_US'
    - name: apt update
      apt: upgrade=dist update_cache=yes

rbenv のセットアップと ruby のインストール

rbenv を使って home に ruby をインストールします。

apt-get も含むので sudo が必要です、sudo 時にパスワードが必要な環境であるときは
ansible-playbook -K ansi_rbenv.yml-K をつけて実行します。

ansi_rbenv.yml
- hosts: localhost
  become: yes
  tasks:
    - name: apt-get installs
      apt: name={{item}} state=present
      with_items:
        - build-essential
        - git
        - libssl-dev
        - zlib1g-dev
        - libreadline6-dev
        - curl
        - wget

- hosts: localhost
  become: no
  vars:
    rubyver: 2.3.1
  tasks:
    - name: get rbenv
      git: repo=https://github.com/rbenv/rbenv.git
           dest=~/.rbenv
    - name: get rbenv plugin
      git: repo=https://github.com/rbenv/ruby-build.git
           dest=~/.rbenv/plugins/ruby-build
    - name: update bashrc
      lineinfile: dest='~/.bashrc' line={{item}}
      with_items:
        - '#rbenv'
        - '[[ -d ~/.rbenv  ]] && \'
        - '  export PATH=${HOME}/.rbenv/bin:${PATH} && \'
        - '  eval "$(rbenv init -)"'
    - name: rbenv - install ruby {{rubyver}}
      shell: bash -lc "$HOME/.rbenv/bin/rbenv install -s {{rubyver}}"
    - shell: bash -lc "$HOME/.rbenv/bin/rbenv global {{rubyver}}"

nvm のセットアップと node.js のインストール

nvm を使って home に node.js をインストールします。

バージョンはお好みで書き換えてください。

ansi_nvm.yml
- hosts: localhost
  become: no
  vars:
    nvmver: v0.31.7
    nodever: v6.5.0
  tasks:
    - name: download nvm
      get_url:
        url: https://raw.githubusercontent.com/creationix/nvm/{{nvmver}}/install.sh
        dest: /tmp/install.sh
    - name: nvm install
      shell: bash -lc "source /tmp/install.sh"
    - file: path=/tmp/install.sh state=absent
    - name: node.js install
      shell: /bin/bash -lc "source ~/.nvm/nvm.sh && nvm install {{nodever}}"

その他メモ

Bash on Ubuntu on Windows ワークファイルを全削除して再インストールする手順。

コマンドプロンプトか PowerShell 上で以下のコマンドを実行する。

lxrun /uninstall /full
lxrun /install
2
4
0

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
  3. You can use dark theme
What you can do with signing up
2
4