Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guide on how to install Swift on Ubuntu

Install Swift on Ubuntu

Requirements

  1. Ubuntu 14.04, 16.04, or 16.10

Step 1 - Dependencies

  1. Open up terminal
  2. Install core deps: sudo apt-get install clang libicu-dev git

Step 1.1 - Ubuntu 14.04 Clang

If you're using Ubuntu 14.04, you need to update to clang 3.6 to prevent errors in the future.

  1. Install updated clang: sudo apt-get install clang-3.6
  2. Update clang: sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
  3. Update clang++: sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

Step 2 - Install SwiftEnv

I put this application in here because it greatly helps with handling multiple versions of Swift.

  1. Make the swiftenv folder: mkdir .swiftenv
  2. Clone the repo: git clone https://github.com/kylef/swiftenv ~/.swiftenv
  3. Add swiftenv to bash profile #1: echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bashrc
  4. Add swiftenv to bash profile #2: echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bashrc
  5. Add swiftenv to bash profile #3: echo 'eval "$(swiftenv init -)"' >> ~/.bashrc
  6. Restart the terminal, or run source ~/.bashrc

Step 3 - Install Swift

Follow the table to know what value to insert in the link below

Ubuntu 14.04 Ubuntu 16.04 Ubuntu 16.10
#1 ubuntu1404 ubuntu1604 ubuntu1610
#2 ubuntu14.04 ubuntu16.04 ubuntu16.10
  1. Install Swift 4.0.3 to swiftenv: swiftenv install https://swift.org/builds/swift-4.0.3-release/#1/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-#2.tar.gz

That's it! Swift 4.0.3 is installed on your Ubuntu device and you can check with swift --version to make sure you're running Swift 4.0.3

@SMR

This comment has been minimized.

Copy link

@SMR SMR commented Nov 27, 2017

Nice

@nourallahtq

This comment has been minimized.

Copy link

@nourallahtq nourallahtq commented Dec 12, 2017

i am trying install Swift 4.0.3 the newest version but not working when i want install Swift every time the terminal give me :

https://swift.org/builds/swift-4.0.3-release/ubuntu1610/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.10.tar.gz

bash: https://swift.org/builds/swift-4.0.3-release/ubuntu1610/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.10.tar.gz: No such file or directory

@mochr

This comment has been minimized.

Copy link

@mochr mochr commented Dec 13, 2017

You have to include the swiftenv install command, like this: swiftenv install https://swift.org/builds/swift-4.0.3-release/ubuntu1610/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.10.tar.gz

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jan 11, 2018

Thanks!

@boourns

This comment has been minimized.

Copy link

@boourns boourns commented Jan 23, 2018

you can also just do swiftenv install 4.0.3 and it'll figure out the URL.

@belozerskiy

This comment has been minimized.

Copy link

@belozerskiy belozerskiy commented Jan 25, 2018

Thanks, it was helpful :)

@MasterSwift

This comment has been minimized.

Copy link

@MasterSwift MasterSwift commented Feb 7, 2018

You are G.O.A.T

@yuriismith

This comment has been minimized.

Copy link

@yuriismith yuriismith commented Apr 2, 2018

Well, I put
swiftenv install https://swift.org/builds/swift-4.0-release/ubuntu1604/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu16.04.tar.gz
and have
home/parallels/.swiftenv/libexec/../libexec/swiftenv-install: line 101: curl: command not found
Can it be caused by parallels?

@drbuckleyjr

This comment has been minimized.

Copy link

@drbuckleyjr drbuckleyjr commented May 17, 2018

Having a similar problem installing on a virtual machine under VMWare Fusion on a Mac Pro running OS X 10.11.6. What I see is:
Downloading https://swift.org/builds/swift-4.0.3-release/ubuntu1604/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.04.tar.gz
/tmp/swiftenv-4.0.3-RELEASE-robertbuckley ~
/home/robertbuckley/.swiftenv/libexec/../libexec/swiftenv-install: line 94: curl: command not found

Everything went as described until that final step

@mickaelicoptere

This comment has been minimized.

Copy link

@mickaelicoptere mickaelicoptere commented Jun 26, 2018

Thanks a lot !

@sus007

This comment has been minimized.

Copy link

@sus007 sus007 commented Jul 6, 2018

@drbuckleyjr Run sudo apt-get update && sudo apt-get install curl libcurl4

@satishbabariya

This comment has been minimized.

Copy link

@satishbabariya satishbabariya commented Oct 20, 2018

Thanks !!!

@tomholub

This comment has been minimized.

Copy link

@tomholub tomholub commented Jul 18, 2019

Full steps, Ubuntu 18.04, Swift 5.0.2:

sudo apt-get update
sudo apt-get -y install curl libcurl4 libcurl4-openssl-dev clang libicu-dev
mkdir ~/.swiftenv
git clone https://github.com/kylef/swiftenv ~/.swiftenv
echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bashrc
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(swiftenv init -)"' >> ~/.bashrc
source ~/.bashrc
swiftenv install https://swift.org/builds/swift-5.0.2-release/ubuntu1804/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu18.04.tar.gz
swift --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.