Troubleshooting & Tools for Swift 🔗
Updated June 21, 2025
Issues with Swift in Terminal 🔗
Reinstall Command Line Tools 🔗
Swift-Bridge error in Terminal. The instructions are aimed at fixing issues related to a broken or misconfigured Swift development environment, specifically those involving the Xcode Command Line Tools toolchain and SDK.
-
Remove the current Command Line Tools installation
To uninstall the existing Command Line Tools, you can run this command:
sudo rm -rf /Library/Developer/CommandLineTools -
Reinstall them
Once removed, reinstall the Command Line Tools by running:
This will trigger a prompt to install the latest version of the Command Line Tools.xcode-select --install -
Ensure the correct toolchain is selected
After the reinstallation, make sure the correct toolchain is selected. You can verify and select the toolchain using:
sudo xcode-select --switch /Library/Developer/CommandLineTools -
Verify the Swift version
Once reinstalled, you should verify the version of Swift to ensure it’s aligned with the correct SDK:
swift --version -
Manually Remove the Redundant Module Map
It looks like the error is coming from two conflicting module.modulemap files (
/Library/Developer/CommandLineTools/usr/include/swift/module.modulemapand/Library/Developer/CommandLineTools/usr/include/swift/bridging.modulemap).You could try removing or renaming one of these files to see if that clears up the conflict:
sudo mv /Library/Developer/CommandLineTools/usr/include/swift/module.modulemap /Library/Developer/CommandLineTools/usr/include/swift/module.modulemap.backupThen, check if Swift works again after that.
-
Check the SDK Path
Ensure that the right SDK is being selected. You can check if the correct SDK is in use by running:
xcrun --sdk macosx --show-sdk-pathIf the path seems wrong or outdated, you can try resetting it with:
sudo xcode-select --reset -
Check for Conflicting Environment Variables
There might be environment variables that are causing conflicts, like
SDKROOTorDEVELOPER_DIR. Try clearing them or setting them explicitly:unset SDKROOT unset DEVELOPER_DIR
Installing Swift on Ubuntu 20.04 🔗
-
Install dependecies
apt update && apt upgrade -y apt install binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata zlib1g-dev -
Download Swift Get the URL for the latest version here: https://www.swift.org/download/
Untarwget https://download.swift.org/swift-5.8.1-release/ubuntu2204/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-ubuntu22.04.tar.gztar xzf swift-5.8.1-RELEASE-ubuntu20.04.tar.gz -
Move files
sudo mv swift-5.8.1-RELEASE-ubuntu20.04 /usr/share/swift -
Add to system
PATHenviroment variableecho "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.zshrcsource ~/.zshrcecho "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bash_profilesource ~/.bash_profile -
Check if installation was successful
swift -v
Make a Swift script into executable 🔗
If you place a Swift script file in usr/local/bin, make it executable then you can run it from anywhere:
chmod a+x tasks.swift
cp tasks.swift /usr/local/bin/tasks
tasks run bar
Swift packages 🔗
See Introducing Packages.
Create a Swift package 🔗
In Terminal, navigate to the folder where you wish to create the package and use this command:
swift package init --type executable --name PACKAGE_NAME
PACKAGE_NAME.
Specify Swift version for a Package 🔗
Add the following at the top of the Package.swift file:
// swift-tools-version: 5.10
See Version history.
Specify a minimum macOS version for a Package 🔗
Add this after the name section of the Package( section in the Package.swift file:
platforms: [
.macOS(.v14)
],