LoginSignup
21
22

More than 5 years have passed since last update.

Swift をMacのターミナルから実行する

Last updated at Posted at 2014-12-19

1. インストールしたXcodeのDeveloperディレクトリのパスを確認

$ xcode-select --print-path

# => /Applications/Xcode.app/Contents/Developer

※ もしここで違うXcodeのパスが表示された場合は、以下のコマンドで修正可能。

# Xcode6.X.app の部分は適宜変えて下さい
$ sudo xcode-select --switch /Applications/Xcode6.X.app/Contents/Developer

2. swift コマンドを使う

Yosemite の場合は今の状態でswiftと打つだけで使用できる。
Mavericks の場合、swiftコマンドは以下の場所にある。
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

なので、ターミナルでswiftとうてばこのコマンドが呼ばれるように設定する。

私がよく使うのは~/.bash_profileなので、今回はこの方法で設定してみる。以下の行を追加。

~/.bash_profile
alias swift='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift'

再読み込み

$ source ~/.bash_profile

実行してみる

$ swift
Welcome to Swift!  Type :help for assistance.
1>  

起動できた。終了はControl + d

21
22
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
21
22