Last active
August 10, 2024 22:18
-
-
Save harrisg/fba19b74bc310e9b2f3542e614430c07 to your computer and use it in GitHub Desktop.
Download and install new version of Swift on Ubuntu 22.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Things you should know: | |
# 1. I'm a terrible bash programmer. | |
# 2. Call with sudo. | |
# 3. Pass in the url of the swift .tar.gz release from https://www.swift.org/download/ . | |
# 4. It checks for an existing file of the same name, and will skip the download if it already exists. | |
# 5. This will install the Swift directory under /opt/swift-x.y.z... and symlink that to /opt/swift . | |
# 6. Put /opt/swift/usr/bin in your path and you can easily upgrade Swift to a new release with this script. | |
# export PATH=/opt/swift/usr/bin:"${PATH}" | |
tmp_dir=$(mktemp -d -t swift-XXXXXXXXXX) | |
cd $tmp_dir | |
url=$1 | |
archive_name=$(basename $url) | |
if [ ! -f "$archive_name" ]; then | |
curl -s -O $url | |
fi | |
tar xzf $archive_name | |
dir_name=$(basename $archive_name .tar.gz) | |
if [ -d /opt/$dir_name ]; then rm -Rf /opt/$dir_name; fi | |
mv $dir_name /opt | |
ln -sfn /opt/$dir_name /opt/swift | |
rm -rf $tmp_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment