LoginSignup
2
2

More than 5 years have passed since last update.

Intel Edisonにndenvをセットアップして複数バージョンのNode.jsを使い分ける

Posted at

準備

あらかじめgitbashをインストールします。
ログインシェルをbashにしておきます。

$ chsh -s /bin/bash

参考:橋本商会 » Intel Edisonにopkgで色々インストールした

ndenvのインストール

 $ git clone https://github.com/riywo/ndenv ~/.ndenv
 $ echo 'export PATH="$HOME/.ndenv/bin:$PATH"' >> ~/.bash_profile
 $ echo 'eval "$(ndenv init -)"' >> ~/.bash_profile
 $ exec $SHELL -l

node-buildのインストール

 $ mkdir .ndenv/plugins
 $ git clone git@github.com:riywo/node-build.git ~/.ndenv/plugins/node-build

パッチを当てる

Edisonに入っている/usr/bin/headコマンドがBusyBox版のため、標準的なheadコマンドとオプションが違うようです。ndenvとnode-buildのスクリプトに書かれているhead -1がエラーになるので、head -n 1に書き直しました。

ndenvの変更箇所

diff --git a/libexec/ndenv b/libexec/ndenv
index 150fbac..9e9816c 100755
--- a/libexec/ndenv
+++ b/libexec/ndenv
@@ -12,7 +12,7 @@ if [ -n "$NDENV_DEBUG" ]; then
   set -x
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | head -n 1)
 if [ -z "$READLINK" ]; then
   echo "ndenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
diff --git a/libexec/ndenv-hooks b/libexec/ndenv-hooks
index 1c8b31d..9418bfd 100755
--- a/libexec/ndenv-hooks
+++ b/libexec/ndenv-hooks
@@ -19,7 +19,7 @@ if [ -z "$NDENV_COMMAND" ]; then
   exit 1
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | head -n 1)
 if [ -z "$READLINK" ]; then
   echo "ndenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1
diff --git a/libexec/ndenv-init b/libexec/ndenv-init
index 3003370..01f1bfe 100755
--- a/libexec/ndenv-init
+++ b/libexec/ndenv-init
@@ -29,7 +29,7 @@ if [ -z "$shell" ]; then
   shell="${shell##*/}"
 fi

-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | head -n 1)
 if [ -z "$READLINK" ]; then
   echo "ndenv: cannot find readlink - are you missing GNU coreutils?" >&2
   exit 1

node-buildの変更箇所

diff --git a/bin/node-build b/bin/node-build
index 1a5fe37..5e9baeb 100755
--- a/bin/node-build
+++ b/bin/node-build
@@ -40,7 +40,7 @@ lib "$1"


 resolve_link() {
-  $(type -p greadlink readlink | head -1) "$1"
+  $(type -p greadlink readlink | head -n 1) "$1"
 }

 abs_dirname() {
@@ -155,7 +155,7 @@ compute_sha1() {
     output="$(shasum -a 1 -b)" || return 1
     echo "${output% *}"
   elif type openssl &>/dev/null; then
-    local openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl |
+    local openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl |
     output="$("$openssl" dgst -sha1 2>/dev/null)" || return 1
     echo "${output##* }"
   elif type sha1sum &>/dev/null; then
@@ -172,7 +172,7 @@ compute_sha2() {
     output="$(shasum -a 256 -b)" || return 1
     echo "${output% *}"
   elif type openssl &>/dev/null; then
-    local openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl |
+    local openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl |
     output="$("$openssl" dgst -sha256 2>/dev/null)" || return 1
     echo "${output##* }"
   elif type sha256sum &>/dev/null; then

使ってみる

試しに、v4.2.4をインストールしてみます。

# インストール可能なバージョンを確認する
$ ndenv install --list
Available versions:
  v0.1.14
  v0.1.15
  v0.1.16
  v0.1.17
  v0.1.18
  v0.1.19
  v0.1.20
  v0.1.21
  v0.1.22
  ...

# v4.2.4をインストールして有効にする。
$ ndenv install v4.2.4
$ ndenv global v4.2.4
$ ndenv versions
  system
* v4.2.4 (set by /home/root/.ndenv/version)

# nodeのバージョンを確認
$ node -v
v4.2.4

# system標準のバージョンに戻す
$ ndenv global system
$ node -v
v0.10.38

これでNodeのバージョンを切り替えて開発できるようになりました。

以上

2
2
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
2