やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

rbenvに必要なディレクトリを用意した

前回のつづき。

開発環境

経緯

  1. はてなブログAPIで予約投稿したい
  2. OAuthなのでAccessToken取得する手続きが必要
  3. 2のためのRubyスクリプト発見
  4. ついでにはてなAPI用のRubyスクリプトもインストールしたいと思ったところで問題発生

Server Error
Server Error
http://ytyaru.hatenablog.com/entry/2017/05/14/000000
http://ytyaru.hatenablog.com/entry/2017/05/15/000000
http://ytyaru.hatenablog.com/entry/2017/05/16/000000

Ruby2.0が必要とわかった。複数バージョン管理するツールrbenvをインストールしようと試み中。

http://ytyaru.hatenablog.com/entry/2017/05/17/000000

.bash/

rbenvの設定に.bashrcファイルを設定する必要があるらしい。

しかし、そもそも.bashディレクトリが存在しなかったので、自分で作ってしまうことにした。

  1. /home/{user}/ディレクトリ配下に.bashディレクトリを作成した
  2. /home/{user}/.bashディレクトリ配下に.bashrcファイルを作成した
  3. 2のファイルに以下を記述した
[[ -d ~/.rbenv  ]] && \
  export PATH=${HOME}/.rbenv/bin:${PATH} && \
  eval "$(rbenv init -)"

ターミナルを再起動させてrbenvを起動したが、前回と同じエラー。

$ rbenv
/usr/lib/rbenv/libexec/rbenv---version: 17 行: cd: /home/mint/.rbenv: そのようなファイルやディレクトリはありません

Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

export

.bashrcに記述したコードの意味を調べてみた。

export環境変数を作成するコマンドらしい。ディレクトリを作成してくれるわけではないらしい。

.rbenv/

/home/{user}/ディレクトリ配下に.rbenv/ディレクトリも作成した。

ターミナルを再起動させてrbenvを起動した。エラーが出ない。OK

$ rbenv
rbenv 0.4.0
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

まとめ

  1. rbenvをインストールする sudo apt-get install rbenv
  2. /home/{user}/ディレクトリ配下に.rbenv/ディレクトリを作成する
  3. /home/{user}/ディレクトリ配下に.bashディレクトリを作成する
  4. /home/{user}/.bashディレクトリ配下に.bashrcファイルを作成する
  5. 4のファイルに以下を記述する
[[ -d ~/.rbenv  ]] && \
  export PATH=${HOME}/.rbenv/bin:${PATH} && \
  eval "$(rbenv init -)"

最後にターミナルを起動してrbenvコマンドを実行する。エラーが出なければ成功。

課題

ruby-buildをインストールしてrbenv installコマンドを使えるようにする。

所感

自分で作ってしまって大丈夫らしい。というか自分で作らないと動作しないのか。