How to install Swift and Vapor on Ubuntu 20.04
This blog post just talk about how to install Swift and Vapor on Ubuntu 20.04.
Let's install Swift first,
- Install some dependencies including clang and Python components
sudo apt install clang libpython2.7 libpython2.7-dev
2. Download Swift for Ubuntu 20.04 from [Download Swift](https://www.swift.org/download/), the latest Swift version is 5.7.3 as of now,
3. After downloading Swift, extract the zip file
tar xzf swift-5.7.3-RELEASE-ubuntu20.04.tar.gz
4. Add Swift path to system PATH environment variable, in my case, the Swift path is /var/www/swift-5.7.3-RELEASE-ubuntu20.04
echo "export PATH=/var/www/swift-5.7.3-RELEASE-ubuntu20.04/usr/bin:$PATH" >> ~/.bashrc source ~/.bashrc
5. To make sure everything works, run the Swift command
and you should see something like below,
Swift version 5.7.3 (swift-5.7.3-RELEASE) Welcome to Swift! Subcommands: swift build Build Swift packages swift package Create and work on packages swift run Run a program from a package swift test Run package tests swift repl Experiment with Swift code interactively Use `swift --help` for descriptions of available options and flags. Use `swift help <subcommand>` for more information about a subcommand.
If you have Swift installed, let's install Vapor Toolbox.
git clone https://github.com/vapor/toolbox.git cd toolbox git checkout <desired version> make install
If the make is not installed, you have to run the below command first,
apt install make
Now check the installation was successful by printing help
And you should see something like below,
Usage: vapor <command> Vapor Toolbox (Server-side Swift web framework) Commands: build Builds an app in the console. clean Cleans temporary files. heroku Commands for working with Heroku. new Generates a new app. run Runs an app from the console. Equivalent to `swift run Run`. The --enable-test-discovery flag is automatically set if needed. supervisor Commands for working with supervisord. xcode Opens an app in Xcode. Use `vapor <command> [--help,-h]` for more information on a command.
Hope it helps,