New-Village

月間ブログ。だいたい1カ月に1回は更新しているようです。

Rubyのバージョン変更 in Nitrous Lite

ついつい日本語のドキュメントを探してしまうのですが、ちゃんと原本を読まないとトラブルの元ですね。Nitrous Liteのドキュメントを翻訳してみました。

やる気がなかったり、わからなかったりで、ところどころ訳が怪しいですが、意味は通っていると思うのでご勘弁を。

 

ツッコミは歓迎です。コメント欄に書いていただければ助かります。

 

インストールとRubyバージョンの管理
Installing and Managing Ruby Versions

RubyはAutopartsを使ってインストールされており、chrubyで管理することができます。利用者は、Autopartsを使って追加でRubyをインストールすることが可能です。
Ruby is installed via Autoparts and can be managed with chruby. You can install additional Ruby versions using Autoparts.

 

現在のバージョンの確認
Check Current Version

利用者は、ターミナルから"ruby -v"を実行することによって、現在利用しているrubyのバージョンを素早く確認することができます。
You can quickly check your current ruby version by running ruby -v in the terminal:

action@ruby-23321:~ $ ruby -v
ruby 1.9 (1.9.3-p545) [x86_64-linux]

 
異なるバージョンのインストール
Install a Different Version

Autopartsで利用可能なRubyのバージョンを確認するためには、"parts search ruby"をターミナルから実行します。ruby1.9、2.0、2.1がリストに表示されているのが確認できると思います(訳者追記:2015年6月2日現在、ruby2.2も選択できるようになっています)。
To view the Ruby versions available in Autoparts, run parts search ruby within the terminal. You will see ruby1.9, 2.0, and 2.1 within the list.

action@ruby-23321:~ $ parts search ruby
chruby (0.3.8) Chruby: Changes the current ruby
ruby2.1 (2.1.2) Ruby 2.1.2: A dynamic programming language with a focus on simplicity and productivity.
ruby1.9 (1.9.3-p545) Ruby 1.9.3: A dynamic programming language with a focus on simplicity and productivity.
ruby2.0 (2.0.0-p451) Ruby 2.0.0: A dynamic programming language with a focus on simplicity and productivity.
ruby_install (0.4.1) Ruby Install: Installs Ruby, JRuby, Rubinius, MagLev or MRuby

Ruby 2.1をインストールするには、以下のコマンドを実行します:
Run the following command to install Ruby 2.1:

parts install ruby2.1

Ruby 2.1はすでにインストール済みで、Rubyのデフォルト・バージョンとして設定されています。
Ruby 2.1 is now installed and should now be your default version of Ruby.

 

訳者追記:"parts install ruby2.x"を実行すると、ターミナルが"=> Activating..." で数分止まります。気長に待つように。また、インストールを完了した後にインストール済みのRubyを利用したい場合は、以下の指示通り、シェルを再起動(consoleを閉じて開き直す)する必要があります。

=> Installed ruby2.2 2.2.0
Please restart your shell session to use the newly installed version of Ruby.

* You can install Bundler by running `gem install bundler`.
* You can switch between installed Ruby versions using `chruby`.
* You can set default Ruby version by editing ~/.ruby-version file.

Read more about chruby at: https://github.com/postmodern/chruby

 
バージョンの切り替え
Switching Versions

ターミナルから"chruby"を実行すると、インストールされているRubyのバージョン一覧が表示されます:
Run chruby in the terminal to view all installed ruby versions:

action@ruby-27340:~ $ chruby
ruby-1.9.3-p545
ruby-2.0.0-p451
* ruby-2.1.1

現在利用しているバージョンにはアスタリスクがついています。バージョンを変更するには(例えば、ruby-1.9.3-p545)、以下のコマンドをターミナルに入力します:
You’ll see that there is an asterisk next to the active version. To change versions (e.g ruby-1.9.3-p545), enter in this command within the terminal:

chruby ruby-1.9.3-p545

次回接続時以降もRubyのデフォルトバージョンを変更するには、"~/.ruby-version"を変更する必要があります。例えば、手軽にRuby 2.1をデフォルトバージョンとしてセットするには、以下のコマンドを実行する必要があります:
In order to change the default version of Ruby which is loaded the next time you connect you will need to edit ~/.ruby-version. For example, to quickly set Ruby 2.1 as your default version you will simply need to run the following command:

echo 'ruby-2.1.1' > .ruby-version

 
Gemのインストール
Installing Gems

利用者はsudo権限を取得せず、普通にインストールすることが可能です。
You can install gems as you normally would, and do not need sudo access.

gem install rails

Bundlerは、複数のgemの管理とプロジェクトにおけるバージョンの管理に使うことができます。以下のコマンドを実行してBundlerをインストールします。
Bundler can be used to manage multiple gems and specific versions within your project. Run the following command to install Bundler:

gem install bundler

Bundler利用に関するより詳細な情報は、公式ドキュメントを参照してください。
For more information on using Bundler, read the official documentation.

 

訳者追記:上記「異なるバージョンのインストール」を実行してからバージョンを変更すると、railsもbundlerもインストールされていませんので、基本的には上記手順を実行しておいたほうが良いと思います(よく分からない人は特に)。

 

引用元

help.nitrous.io

Python3が使いたい in Nitrous.is

Nitrous.IOでPythonのBoxを作ると、現時点(2015年4月22日)ではPython2.7.6環境が作成されます。

違うバージョンのPythonを使いたい場合は、virtualenvなるツールで使いたいPythonバージョンの環境を作ってあげればいいようです。ちょー便利?Java環境変数を変えるようなもんか?

とりあえず、以下手順。

切り替え可能なPythonの一覧を調べる

~$ ls /usr/bin/python*

環境を作る

/usr/bin/python3.3 の部分は、上記で調べた、自分が使いたいPythonまでのパスを指定します。py3env の部分は、任意の開発環境名を指定します。

~$ virtualenv -p /usr/bin/python3.3 env
Running virtualenv with interpreter /usr/bin/python3.3
Using base prefix '/usr'
New python executable in devEnv/bin/python3.3
Also creating executable in devEnv/bin/python
Installing setuptools, pip...done.

環境を切り替える

~$ source env/bin/activate

参考

help.nitrous.io

 

オブジェクト指向ぽいシェルスクリプトの使い方

使いやすそうだったので書いてみました。
いろいろテストしてみたら、意外と使いにくいので、結局使っていないのですが…

if文の条件文にファンクション名をバッククオートで囲って書いてあげると、ファンクションの戻り値でif文の判定を行ってくれます。

ちなみにreturnが無くても、echoで"true"という文字列を出力している場合は、これを条件判定に使ってくれます(trueの場合はtrue、それ以外はfalse)。

なお、returnとechoが一つのファンクションに存在する場合は、echoの結果が優先されるようですので注意してください。

追記:echo も return もない場合は、一番最後に実行されたコマンドのエラーコードを条件判定に使ってくれるようです。 

順番としては、echo "true/false" > return 0/1 > 最後に実行されたコマンドのエラーコード みたいです。

 

eclipseでターミナル

Play Framework開発を便利にするためのカスタマイズその1。

EclipseのHelp > Eclipse Marketplaceを起動して、terminalで検索すると、Google社製のターミナルプラグインが表示されます。

f:id:New-Village:20141221185152p:plain

ウィザードに従って、同プラグインをインストールして、eclipseを再起動します。
再起動後に Window > Show View > Other を選択します。Show View ウィンドウが表示されるので、General > Terminalを選択して、OKを押します。

f:id:New-Village:20141221185551p:plain

eclipseからターミナルにアクセスできるようになります。

f:id:New-Village:20141221185929p:plain