How to install swift on Ubuntu

How to install swift on Ubuntu

While Apple doesn’t have pre-compiled versions for anything beyond Ubuntu 16.10, that didn’t stop me from trying 🙂


All you need to do is download and decompress the .tar.gz file. That can be done with the following two lines of bash:

tar xzvf swift-4.0.3-RELEASE-ubuntu16.10.tar.gz

and you should be able to run:

cd swift-4.0.3-RELEASE-ubuntu16.10/usr/bin/

and get a swift shell-thingie. Anyways, if you get an error, the best advice I can give is Google it, and you’ll probably have to install a package or two. Funnily enough, I didn’t need the packages the Apple tutorial says you need, and everything worked fine.

Adding it to your path

So, now all you need is to add this into your path. I like to create a folder called .swift in my home directory, so I don’t see it, but can still add to my path. Here’s the commands to do that:

mv swift-4.0.3-RELEASE-ubuntu16.10 .swift

and you can now run swift without needing the full path. But this will not work if you start a new session. To do that, you need to add the last line into your .bashrc file, so here’s the one-line bash way of doing that:

echo 'PATH=$PATH:~/.swift/usr/bin' >> ~/.bashrc

Be sure to use single quotes, or else the variable will get expanded into the current path, which we don’t want in case it changes later. You should now be able to start a new bash session and have access to the swift commands.

All users

If you want something accessible to all users, then put the .swift folder into something like /home, or anywhere everyone has access to with the smallest chance of breaking anything. I once deleted the entire /usr folder while doing this, and that wasn’t fun to recover.

Anyways, let me know if this worked in the comments below!

Leave a Reply(Markdown is On)

%d bloggers like this: