LoginSignup
12
6

More than 5 years have passed since last update.

claspの導入(Mac)

Last updated at Posted at 2019-02-10

claspの導入理由

Google Apps Scriptのソース管理をgitで行いたい。
好きなエディタで開発したい。
以上。

Homebrewの導入

公式サイト : https://brew.sh/index_ja

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

上記のコードをターミナルで実行する。
終了したら、無事インストールができたのかバージョンを確認する。

git --version

余談
私はここでエラーが出てgitをインストールできなかったが、MacのOSをバージョンアップすると上手くいった。

node.jsのインストール

Homebrewでnodebrewをインストールする。

brew install nodebrew
nodebrew -v
nodebrew setup
nodebrew install-binary latest

余談
nodebrew setup をせずに最新版のnode.jsをインストールしようとしたら失敗したので、setup大事。忘れずに実行する。

nodebrew list

上記のコマンドでインストール済みバージョンが分かる。
下のcurrentは使用中のバージョン。私の場合はnoneだった。
なので使用するバージョンを指定する。

nodebrew use v11.9.0
nodebrew list

再び使用可能なバージョンを確認すると、currentが指定したバージョンになっているはず。
次に実行パスを通す。

echo "export PATH=\$xxxxx/.nodebrew/current/bin:\$PATH" >> ~/.bashrc

xxxxxの部分は人による。
深く考えずにnodebrewのインストール時に表示されたパスを貼り付ければOK。
(下記の表示があったはず)

========================================
Export a path to nodebrew:

export PATH=$xxxxx/.nodebrew/current/bin:$PATH
========================================

.bash_profileで.bashrcの設定が読み込まれるようにする。
そして、.bash_profileの編集はviで行うと思うので以下を参考に。

cd
ls -a
vi ~/.bash_profile

ホームディレクトリへ移動し、.bash_profileを開く。ない場合は作る。

if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi

iでINSERTモードに変更し、上記の設定を書き込む。
escキーでコマンドモードに変更。
:wで上書き保存。
:qでvi終了。
設定を反映させるためにターミナルを終了する。

node -v
npm -v

これでバージョンが表示されればOK!

余談
このあとviコマンドが使えなくなったので、設定を編集しにいきました。

/usr/bin/vi ~/.bash_profile

.bash_profileに以下を記載

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

再び設定を反映させるためにターミナルを終了。
これでコマンドが使用できるようになったが、今度はnodeのバージョンが表示されず。
以下を実行して、ようやく完了。困っちゃうね。

source .bashrc

claspのインストール

npm i @google/clasp -g

参考:
claspを使い、Google Apps Scriptプロジェクトをgitでバージョン管理する
GAS のGoogle謹製CLIツール clasp
Google Apps Scriptの新しい3つの機能 その③ CLI Tool Clasp
MacでPATHを通す

12
6
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
12
6