swiftenv allows you to easily install, and switch between multiple versions of Swift.
This project was heavily inspired by pyenv.
swiftenv allows you to:
- Change the global Swift version, per user.
- Set a per-project Swift version.
- Allows you to override the Swift version with an environmental variable.
## Installation
NOTE: If you're on OS X, consider installing with Homebrew.
-
Check out swiftenv, we recommend
~/.swiftenv
(but it can be installed elsewhere as long as you setSWIFTENV_ROOT
).$ git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
-
Configure environment.
For Bash:
$ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile $ echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile
NOTE: On some platforms, you may need to modify
~/.bashrc
instead of~/.bash_profile
.For ZSH:
$ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.zshenv $ echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.zshenv $ echo 'eval "$(swiftenv init -)"' >> ~/.zshenv
For Fish:
$ echo 'setenv SWIFTENV_ROOT "$HOME/.swiftenv"' >> ~/.config/fish/config.fish $ echo 'setenv PATH "$SWIFTENV_ROOT/bin" $PATH' >> ~/.config/fish/config.fish $ echo 'status --is-interactive; and . (swiftenv init -|psub)' >> ~/.config/fish/config.fish
For other shells, please open an issue and we will visit adding support.
-
Restart your shell so the changes take effect.
You can install swiftenv using the Homebrew package manager on OS X.
-
Install swiftenv
$ brew install kylef/formulae/swiftenv
-
Then configure the shims and completions by adding the following to your profile.
For Bash:
$ echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.bash_profile
NOTE: On some platforms, you may need to modify
~/.bashrc
instead of~/.bash_profile
.For ZSH:
$ echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.zshrc
For Fish:
$ echo 'status --is-interactive; and . (swiftenv init -|psub)' >> ~/.config/fish/config.fish
Displays the current active Swift version and why it was chosen.
$ swiftenv version
2.2 (set by /home/kyle/.swiftenv/version)
Lists all installed Swift versions, showing an asterisk next to the currently active version.
$ swiftenv versions
2.2
* 2.2-SNAPSHOT-2015-12-10-a (set by /home/kyle/.swiftenv/version)
Sets the global version of Swift to be used by writing to the
~/.swiftenv/version
file. This version can be overridden by
application-specific .swift-version
file, or by setting the SWIFT_VERSION
environment variable.
$ swiftenv global 2.2
$ swiftenv global
2.2
Sets the local application-specific Swift version by writing the version to a
.swift-version
file in the current directory. This version overrides the
global version and can also be overridden by th SWIFT_VERSION
environment
variable.
$ swiftenv local 2.2
$ swiftenv local
2.2
Installs a version of Swift. This supports any binary release provides by
Apple. For example, a 2.2 snapshots such as 2.2-SNAPSHOT-2016-01-11-a
.
You may also specify 2.2-dev
to build Swift from source, this will require
all of the dependencies mention on
Swift system
requirements. It is
important to note that the Swift Package Manager will not be installed with
2.2-dev
as Swift Package Manager is still in early development and it won't
be included in 2.2, however it is available in the development binary snapshots.
$ swiftenv install 2.2-SNAPSHOT-2016-01-11-a
Downloading 2.2-SNAPSHOT-2016-01-11-a from https://swift.org/builds/ubuntu1510/swift-2.2-SNAPSHOT-2016-01-11-a/swift-2.2-SNAPSHOT-2016-01-11-a-ubuntu15.10.tar.gz
You may also use URLs to a Swift Binary package URL from Swift Snapshots as a parameter
$ swiftenv install https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx.pkg
Downloading https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx.pkg
Password:
You may also manually install Swift and make it accessible to swiftenv. Custom
Swift installations can either be placed in a directory using the correct
version number at ~/.swiftenv/versions/VERSION
, or can be symbolic
linked into the version directory.
It is expected that all dependencies are already installed for running Swift, please consult the Swift website for more information.
NOTE: After manually installing a version of Swift, it's recommended that
you run swiftenv rehash
to update the shims.
Uninstalls a specific Swift version.
$ swiftenv uninstall 2.2
Installs shims for the Swift binaries. This command should be ran after you manually install new versions of Swift.
$ swiftenv rehash
Displays the full path to the executable that would be invoked for the selected version for the given command.
$ swiftenv which swift
/home/kyle/.swiftenv/versions/2.2/usr/bin/swift
$ swiftenv which lldb
/home/kyle/.swiftenv/versions/2.2/usr/bin/lldb