Last active
July 17, 2025 08:37
-
-
Save valeriyvan/265a90e42135e9284a49dd9c9613e2d6 to your computer and use it in GitHub Desktop.
Script to install dependencies for building Swift on Ubuntu 22.04 LTS
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
# Install dependencies for building Swift on Ubuntu 22.04 LTS | |
# Compiled from Dokerfile https://github.com/swiftlang/swift-docker/blob/main/swift-ci/main/ubuntu/24.04/Dockerfile | |
# as recommended in https://github.com/swiftlang/swift/blob/main/docs/HowToGuides/GettingStarted.md#linux | |
# This could be used as script to run on initial Digital Ocean droplet boot up. | |
# 1. Create a build user (optional, but recommended for safety) | |
#sudo groupadd -g 998 build-user | |
#sudo useradd -m -r -u 998 -g build-user build-user | |
# 2. Set non-interactive frontend (to suppress prompts during install) | |
export DEBIAN_FRONTEND=noninteractive | |
# 3. Install build dependencies | |
sudo apt-get update | |
sudo apt-get install -y \ | |
build-essential \ | |
clang \ | |
cmake \ | |
git \ | |
icu-devtools \ | |
libc++-18-dev \ | |
libc++abi-18-dev \ | |
libcurl4-openssl-dev \ | |
libedit-dev \ | |
libicu-dev \ | |
libncurses5-dev \ | |
libpython3-dev \ | |
libsqlite3-dev \ | |
libxml2-dev \ | |
ninja-build \ | |
pkg-config \ | |
python3-six \ | |
python3-pip \ | |
python3-pkg-resources \ | |
python3-psutil \ | |
python3-setuptools \ | |
rsync \ | |
swig \ | |
systemtap-sdt-dev \ | |
tzdata \ | |
uuid-dev \ | |
zip \ | |
curl \ | |
gpg | |
# 4. Install Python dependencies | |
wget https://raw.githubusercontent.com/swiftlang/swift-docker/main/swift-ci/dependencies/requirements.txt -O /tmp/requirements.txt | |
sudo pip3 install -r /tmp/requirements.txt --break-system-packages | |
# 5. Download and install Swift | |
SWIFT_PLATFORM=ubuntu24.04 | |
SWIFT_VERSION=5.10.1 | |
SWIFT_BRANCH=swift-${SWIFT_VERSION}-release | |
SWIFT_TAG=swift-${SWIFT_VERSION}-RELEASE | |
SWIFT_WEBROOT=https://download.swift.org | |
SWIFT_PREFIX=/opt/swift/${SWIFT_VERSION} | |
ARCH_NAME=$(dpkg --print-architecture) | |
case "${ARCH_NAME##*-}" in | |
amd64) OS_ARCH_SUFFIX='';; | |
arm64) OS_ARCH_SUFFIX='-aarch64';; | |
*) echo "error: unsupported architecture: '$ARCH_NAME'"; exit 1;; | |
esac | |
SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)$OS_ARCH_SUFFIX" | |
SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_TAG/$SWIFT_TAG-$SWIFT_PLATFORM$OS_ARCH_SUFFIX.tar.gz" | |
SWIFT_SIG_URL="$SWIFT_BIN_URL.sig" | |
# Now download, verify, and extract Swift: | |
sudo mkdir -p $SWIFT_PREFIX | |
cd /tmp | |
curl -fsSL "$SWIFT_BIN_URL" -o swift.tar.gz | |
curl -fsSL "$SWIFT_SIG_URL" -o swift.tar.gz.sig | |
curl -fSsL --compressed https://swift.org/keys/all-keys.asc | gpg --import - | |
gpg --batch --verify swift.tar.gz.sig swift.tar.gz | |
sudo tar -xzf swift.tar.gz --directory $SWIFT_PREFIX --strip-components=1 | |
sudo chmod -R o+r $SWIFT_PREFIX/usr/lib/swift | |
rm swift.tar.gz swift.tar.gz.sig | |
# 6. Add Swift to your PATH | |
#Add this to your ~/.bashrc or ~/.profile: | |
#export PATH="$SWIFT_PREFIX/usr/bin:$PATH" | |
#Then reload your shell: | |
#source ~/.bashrc | |
# 7. (Optional) Switch to the build-user | |
#sudo su - build-user | |
#cd ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment