swiftenv allows you to easily install, and switch between multiple versions of Swift.

Last update: May 6, 2022

Swift Version Manager

swiftenv allows you to easily install, and switch between multiple versions of Swift.

This project was heavily inspired by pyenv.

swiftenv screenshot

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.

The User Guide

GitHub

https://github.com/kylef/swiftenv
Comments
  • 1. Doesn't seem to work with Swift 4

    I'm on Sierra, 10.12.6. I ran swiftenv install 4.0 and then swiftenv global 4.0. swiftenv global showed the global version was 4.0, but swift --version still showed 3.1. Could it be I was doing something wrong?

    Reviewed by denpazakura at 2017-08-16 14:45
  • 2. Using global does not change the actually `swift` pointing

    How to fix this?

    ➜  ~ swiftenv global
    4.1.2
    ➜  ~ swift --version
    Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
    Target: x86_64-apple-darwin17.7.0
    
    Reviewed by Lucashuang0802 at 2018-10-01 23:09
  • 3. install fails on FreeBSD

    First off thank you for building swiftenv. I've been using it on my mac for a while now :).

    I'm not too familiar with FreeBSD, but I installed the depenceids that you detailed in the wiki. After that I tried to build swift on FreeBSD and I run into this error:

    [[email protected] ~]$ swiftenv install 3.0-dev
    Found swift, skipping download
    Found compiler-rt, skipping download
    Found llvm, skipping download
    Found clang, skipping download
    Found lldb, skipping download
    Found cmark, skipping download
    Found swiftpm, skipping download
    Found llbuild, skipping download
    Found swift-corelibs-xctest, skipping download
    Found swift-corelibs-foundation, skipping download
    Found swift-corelibs-libdispatch, skipping download
    Building Swift
    This may take a very long time...
    Building Swift failed
    Check out the logfile for more information: /home/freebsd/.swiftenv/tmp/swiftenv-build-3.0-dev/swiftenv-build.20160608060410.1397.log
    You can inspect or delete the working tree at: /home/freebsd/.swiftenv/tmp/swiftenv-build-3.0-dev
    

    If I cat the log file this is what I get:

    [[email protected] ~]$ cat /home/freebsd/.swiftenv/tmp/swiftenv-build-3.0-dev/swiftenv-build.20160608055536.1199.log
    Cloning into 'swift'...
    Checking out files: 100% (10799/10799), done.
    Cloning into 'compiler-rt'...
    Cloning into 'llvm'...
    Checking out files: 100% (20127/20127), done.
    Cloning into 'clang'...
    Checking out files: 100% (11768/11768), done.
    Cloning into 'lldb'...
    Checking out files: 100% (5479/5479), done.
    Cloning into 'cmark'...
    Cloning into 'swiftpm'...
    Cloning into 'llbuild'...
    Cloning into 'swift-corelibs-xctest'...
    Cloning into 'swift-corelibs-foundation'...
    Cloning into 'swift-corelibs-libdispatch'...
    usage: 
      build-script [-h | --help] [OPTION ...]
      build-script --preset=NAME [SUBSTITUTION ...]
    build-script: error: unknown argument: --build-jobs
    

    Any ideas?

    Reviewed by hamin at 2016-06-08 06:06
  • 4. Swift 4.0 on macOS?

    Swift 4.0 was finally released yesterday, and on macOS, it's part of the Xcode 9 without a pkg installer as development snapshots. By looking at this commit https://github.com/kylef/swiftenv-api/commit/12e7c76e0fda1f8fdd6edc47c5554f4174e2e1f5, I don't see it for macOS, which is understandable.

    My question is, I have a .swift-version file, which is set to 4.0, and it works in Linux environments. How should I set swiftenv up properly to use 4.0 on macOS? Thanks!

    Reviewed by ryuichis at 2017-09-20 15:44
  • 5. swiftenv install 3.0 fails with "version `3.0' is not installed" on TravisCi's xcode7.2 image

    I've set up a Travis CI build to install swift 3.0 on their xcode7.2 image. When I configure it to install 3.0, I see:

    $ swiftenv install --verbose 3.0
    Checking for a URL for the 3.0 on osx.
    Installing 3.0 from https://swift.org/builds/swift-3.0-release/xcode/swift-3.0-RELEASE/swift-3.0-RELEASE-osx.pkg on osx.
    Downloading https://swift.org/builds/swift-3.0-release/xcode/swift-3.0-RELEASE/swift-3.0-RELEASE-osx.pkg
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  254M  100  254M    0     0  11.1M      0  0:00:22  0:00:22 --:--:-- 12.5M
    installer: Package name is Swift Open Source Xcode Toolchain
    installer: Installing at base path /
    installer: The install was successful.
    3.0 has been installed.
    swiftenv: version `3.0' is not installed
    

    I think this is because https://github.com/kylef/swiftenv/blob/master/share/swiftenv-install/3.0#L11 will use https://swift.org/builds/swift-3.0-release/xcode/swift-3.0-RELEASE/swift-3.0-RELEASE-osx.pkg to install version 3.0. That package installs to /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain, but https://github.com/kylef/swiftenv/blob/master/libexec/swiftenv-prefix#L29 instead checks for /Library/Developer/Toolchains/swift-3.0.xctoolchain (without the -RELEASE).

    I can't replicated it locally, as I've installed Xcode 8 & swiftenv-prefix finds /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift, and its version is

    Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
    Target: x86_64-apple-macosx10.9
    

    which is recognised by https://github.com/kylef/swiftenv/blob/master/libexec/swiftenv-prefix#L47

    Reviewed by dgholz at 2016-10-11 05:25
  • 6. Issues when installing on Ubuntu 16.04

    Hi, I'm trying to install both 2.2 and 3.0-dev versions, and I'm getting the following error message in the logs: Can't find source directory for ninja (tried ~/.swiftenv/tmp/swiftenv-build-3.0-dev/ninja)

    Do I need to clone github.com/martine/ninja in that directory? If so, which version do I need? Thanks.

    Reviewed by dlaynes at 2016-04-30 22:05
  • 7. c++ command messed up

    Sorry for the hazy title but wanted to file this issue to keep track of it and add more info to it as I find time investigating this.

    I'm on OSX 10.10.3. I've installed swiftenv and it seemed to work well, until some system tool tried to call c++ which resulted in empty stdout-put.

    which c++ yielded

    ~/.swiftenv/shims/c++
    

    contents of ~/.swiftenv/shims/c++ is this:

    #!/usr/bin/env bash
    set -e
    exec "/usr/local/Cellar/swiftenv/0.2.0/bin/../libexec/swiftenv" exec "c++" "[email protected]"
    

    Commenting out swiftenv in my .zshrc resolves the issues and I'm currently falling back to the system c++.

    Let's play a game...

    Reviewed by kimar at 2016-01-24 21:52
  • 8. Add support for Centos7/8, Amazonlinux2 and aarch64

    To get this to work I had to make two changes

    1. Instead of using lsb_release to identify which Linux we are running I parse the /etc/os-release file. This file is more likely to be available.
    2. I don't use ask swiftenv-api.fuller.li to get the URL for the swift release. The swift team have a standard naming scheme for swift releases so you should need to create a new entry for each new release of swift.

    Closes #138, #172

    Reviewed by adam-fowler at 2021-08-20 06:21
  • 9. swift-build exists in shims when 2.2 is active.

    When switching from a 3.0 version of Swift back to a 2.2 version, the shims still contain swift-build. This causes detection scripts to assume they can use SPM when they can't.

    Reviewed by helje5 at 2016-06-14 22:16
  • 10. Thinking of a possible SourceKitten integration for Linux

    Hi!

    You may know SourceKitten. It's a framework and command line tool that allows interaction with SourceKit. This has made possible tools like SwiftLint and SourceKittenDaemon. For usage within Linux, the only requirement is that the environment variable LINUX_SOURCEKIT_LIB_PATH is set to $SWIFT_BINARIES_HOME/usr/lib/. Do you think swiftenv could provide integration with this?

    Any help you'd need I can provide. It's very important for me that something as important as SourceKit is accessible within Linux, because it will allow users to have IDEs with autocompletion and linting.

    Please tell me if this is possible. -- Félix

    Reviewed by felix91gr at 2018-04-07 01:36
  • 11. swiftenv causes some of swift compiler tests to fail

    Hi Kyle, I really like swiftenv, thank you for making this awesome product! However, I have some issue with swiftenv and swift compiler tests right now.

    I built swift complier from apple/swift repo, and I ran swift compiler tests by $ swift/utils/build-script --test. When swiftenv is isntalled, 346 tests fails as "Unexpected Failures" with the following error (this is one of the failed test result messages):

    ********************
    FAIL: Swift(macosx-x86_64) :: PlaygroundTransform/high_performance.swift (326 of 2938)
    ******************** TEST 'Swift(macosx-x86_64) :: PlaygroundTransform/high_performance.swift' FAILED ********************
    Script:
    --
    rm -rf /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp
    mkdir -p /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp
    cp /Users/keitaito/Swift/swift-source/swift/test/PlaygroundTransform/high_performance.swift /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp/main.swift
    xcrun --toolchain default --sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc -target x86_64-apple-macosx10.9  -module-cache-path '/var/folders/4y/_c55p9_170n54jw_s64mx_c80000gn/T/swift-testsuite-clang-module-cacheR0Chhb' -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks    -Xfrontend -playground -Xfrontend -playground-high-performance -Xfrontend -debugger-support -o /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp/main /Users/keitaito/Swift/swift-source/swift/test/PlaygroundTransform/Inputs/PlaygroundsRuntime.swift /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp/main.swift
    /Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PlaygroundTransform/Output/high_performance.swift.tmp/main | /Users/keitaito/Swift/swift-source/swift/utils/PathSanitizingFileCheck --sanitize 'BUILD_DIR=/Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64' --sanitize 'SOURCE_DIR=/Users/keitaito/Swift/swift-source/swift' --use-filecheck '/Users/keitaito/Swift/swift-source/build/Ninja-DebugAssert/llvm-macosx-x86_64/./bin/FileCheck' /Users/keitaito/Swift/swift-source/swift/test/PlaygroundTransform/high_performance.swift
    --
    Exit Code: 1
    
    Command Output (stderr):
    --
    mkdir: /.swiftenv: Permission denied
    <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
    

    Here is the overall tests result with swiftenv:

    ********************
    Testing Time: 815.15s
    ********************
    Failing Tests (346):
        Swift(macosx-x86_64) :: SILOptimizer/specialize_partial_apply.swift
        Swift(macosx-x86_64) :: SILOptimizer/let_properties_opts_runtime.swift
        Swift(macosx-x86_64) :: SILOptimizer/capture_propagation_linkage.swift
        ... (this is pretty long for 346)
        Swift(macosx-x86_64) :: Reflection/box_descriptors.sil
        Swift(macosx-x86_64) :: Runtime/backtrace.swift
        Swift(macosx-x86_64) :: SILGen/coverage_smoke.swift
    
      Expected Passes    : 2520
      Expected Failures  : 8
      Unsupported Tests  : 64
      Unexpected Failures: 346
    *** Failed while running tests for swift (check-swift-macosx-x86_64)
    swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
    

    Full failing tests list is here: https://gist.github.com/keitaito/0247ab6cfd6e86f0f636a7d3306c9012

    After the above failure, I uninstalled swiftenv, and I tried swift compiler tests again. This time, there are no "Unexpected Failures", and all tests are finished correctly. Here is the overall tests result:

    Testing Time: 887.59s
      Expected Passes    : 2866
      Expected Failures  : 8
      Unsupported Tests  : 64
    -- check-swift-macosx-x86_64 finished --
    --- Finished tests for swift ---
    

    Do you have any idea why swiftenv causes this issue, and how can I fix it?

    I just only installed swiftenv, and no other versions of swift installed via swiftenv.

    $ swiftenv versions
    * system
      3.0
    
    $ swiftenv version
    system (set by /Users/keitaito/.swiftenv/version)
    

    OS: OS X El Capitan version 10.11.6 Installed Xcode: Xcode 8 Built swift compiler directory name: Ninja-DebugAssert -> swift-macosx-x86_64

    Sorry in advance if my explanation here is not clear enough. Please let me know if you need any other information. Thank you.

    Reviewed by keitaito at 2016-09-19 06:30
  • 12. Support Windows binaries

    The Swift toolchain recently added official support for Windows, so it would be nice to have swiftenv support it. Or would that be impossible given that swiftenv is written in Bash?

    Reviewed by fwcd at 2020-10-04 00:11
  • 13. Swiftenv as the official Swift version manager?

    Not an issue... more of a suggestion. This is a great product and really should be THE official way to install Swift. Have you thought about proposing this to the Swift team as the official, first-class way to manage Swift toolchains? This is great as-is, but would be even better if built-in. This could make the Swift installation process as simple as installing swiftenv, then grabbing the latest version of Swift.

    brew install swiftenv
    swiftenv install latest
    
    Reviewed by reuschj at 2020-08-27 04:57
  • 14. no such command: swift-format

    I'm not sure if this is just a user error or not, but I get the following error attempting to use swift-format alongside swiftenv:

    $ swift format
    no such command: swift-format
    $ which -a swift-format
    /Users/mplewis/.swiftenv/shims/swift-format
    /usr/local/bin/swift-format
    

    As potentially indicated above, this is using the homebrew-installed version of swift-format. Is this a bug, or simply something I've configured or set up wrong?

    Reviewed by MPLew-is at 2020-06-17 07:20
  • 15. [BUG] Switching versions doesn't appear to work.

    swiftenv 1.4.0 installed via homebrew

    Overriding swift toolchain with one of installed version by local or global doesn't seem to do anything even though

    swiftevn points to toolchain

    $ swiftenv local
    wasm-DEVELOPMENT-SNAPSHOT-2020-06-02-a192-168-1-147:swift-ui-asm 
    

    but running command with swift says otherwise.

    $ swift --version
    Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
    Target: x86_64-apple-darwin19.4.0
    
    Reviewed by shial4 at 2020-06-07 12:50
  • 16. Install latest Swift with DBUILD_SHARED_LIBS set to NO

    Currently there's SR-7039 open which prevents me from installing the amazing Mint package manager on my Ubuntu 16.04 CI running with Swift 4.1.3 (I also tried 4.0.3 and Snapshot-2018-08-02 without success). Here's the related issue on that on the Mint project.

    In the discussion of SR-7039 Joel Saltzman explains a workaround in a comment which basically means I have to pass a different parameter when installing swift-corelibs-libdispatch during the Swift installation. So I was thinking of just doing that manually by running the following additional commands after installing Swift via swiftenv install 4.1.3 like so:

    # Workaround for issue [SR-7039]
    sudo apt-get install cmake ninja-build clang systemtap-sdt-dev libbsd-dev linux-libc-dev
    cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_SHARED_LIBS=NO <path-to-source>
    ninja
    ninja install
    

    But I actually have no idea what to specify to <path-to-source> or if this approach could even work after having already installed Swift. Is there a way I can pass the parameter -DBUILD_SHARED_LIBS=NO when installing Swift with swiftenv?

    Thanks for any help!

    Reviewed by Jeehut at 2018-08-04 09:43
Related tags
AVXCAssets Generator takes path for your assets images and creates appiconset and imageset for you in just one click
AVXCAssets Generator takes path for your assets images and creates appiconset and imageset for you in just one click

AVXCAssets Generator Often while developing an app, We ran into a condition when we need to scale images to each and every aspect ratios for icons and

May 20, 2022
Automatically build and rebuild Xcode image catalogs for app icons, universal images, and more
Automatically build and rebuild Xcode image catalogs for app icons, universal images, and more

Better asset workflow for iOS developers. Generate Xcode image catalogs for iOS / OSX app icons, universal images, and more.

Mar 31, 2022
Build native iOS, Android, and Web apps with Capacitor and Remix.run 💿

This repository holds production ready Capacitor templates for building native mobile applications using Remix. Using Capacitor, you can quickly build out a native mobile application for iOS and Android using web technology, such as Remix.

May 20, 2022
Swift CLI for strong-typing images, colors, storyboards, fonts and localizations

Shark Shark is a Swift command line tool that generates type safe enums for your images, colors, storyboards, fonts and localizations. Because Shark r

Dec 22, 2021
Strong typed, autocompleted resources like images, fonts and segues in Swift projects
Strong typed, autocompleted resources like images, fonts and segues in Swift projects

R.swift Get strong typed, autocompleted resources like images, fonts and segues in Swift projects Why use this? It makes your code that uses resources

May 13, 2022
Xcode storyboards diff and merge tool.
Xcode storyboards diff and merge tool.

StoryboardMerge Storyboard diff and merge tool which: compares and merges two storyboard files, provides an automatic merge-facility, The storyboardin

Apr 1, 2022
An adorable little framework and command line tool for interacting with SourceKit.

SourceKitten An adorable little framework and command line tool for interacting with SourceKit. SourceKitten links and communicates with sourcekitd.fr

May 12, 2022
Soulful docs for Swift & Objective-C
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

May 22, 2022
Laurine - Localization code generator written in Swift. Sweet!
Laurine - Localization code generator written in Swift. Sweet!

Author's note: Thanks everyone for making Laurine the TOP trending Swift repository in the world - this is amazing and very heart-warming! But this is

May 2, 2022
An Xcode Plugin to convert Objective-C to Swift
An Xcode Plugin to convert Objective-C to Swift

XCSwiftr Convert Objective-C code into Swift from within Xcode. This plugin uses the Java applet of objc2swift to do the conversion. Noticed that the

Apr 4, 2022
Swift autocompleter for Sublime Text, via the adorable SourceKitten framework
Swift autocompleter for Sublime Text, via the adorable SourceKitten framework

SwiftKitten SwiftKitten is a Swift autocompleter for Sublime Text, via the adorable SourceKitten framework. Faster than XCode ! This package is new an

Jan 21, 2022
SwiftGen is a tool to automatically generate Swift code for resources of your projects
SwiftGen is a tool to automatically generate Swift code for resources of your projects

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

May 18, 2022
The best command-line tool to install and switch between multiple versions of Xcode.
The best command-line tool to install and switch between multiple versions of Xcode.

The best command-line tool to install and switch between multiple versions of Xcode.

May 14, 2022
The easiest way to install and switch between multiple versions of Xcode - with a mouse click.
The easiest way to install and switch between multiple versions of Xcode - with a mouse click.

Xcodes.app The easiest way to install and switch between multiple versions of Xcode. If you're looking for a command-line version of Xcodes.app, try x

May 18, 2022
XLPagerTabStrip is a Container View Controller that allows us to switch easily among a collection of view controllers
XLPagerTabStrip is a Container View Controller that allows us to switch easily among a collection of view controllers

XLPagerTabStrip is a Container View Controller that allows us to switch easily among a collection of view controllers. Pan gesture can be used to move on to next or previous view controller. It shows a interactive indicator of the current, previous, next child view controllers.

May 16, 2022
UIImageView subclass that allows you to display a looped video and dynamically switch it.
UIImageView subclass that allows you to display a looped video and dynamically switch it.

AKVideoImageView Motivation AKVideoImageView was created because I wasn't satisfied with the standard AVPlayer when I was implementing a video backgro

Apr 5, 2022
A command line tool to easily install and browse Xcode templates

?? XTrail A command line tool to easily install and browse Xcode templates. Usage The general invocation syntax for xtrail is as follows: xtrail <subc

Dec 16, 2021
Install Agora Audio SDK for macOS easily with Swift Package Manager
Install Agora Audio SDK for macOS easily with Swift Package Manager

Agora Swift Package Manager Install Agora Audio SDK for macOS easily with Swift Package Manager. Click here for full documentation. Installation Add t

Nov 29, 2021
Tip-Calculation- - A program for calculate the tip. You can easily calculate it and you can split money easily
Tip-Calculation- - A program for calculate the tip. You can easily calculate it and you can split money easily

Tip-Calculation- It is a program for calculate the tip. You can easily calculate

Jan 13, 2022