Skip to content

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.

  1. 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
    

  2. Reinstall them

    Once removed, reinstall the Command Line Tools by running:

    xcode-select --install
    
    This will trigger a prompt to install the latest version of the Command Line Tools.

  3. 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
    
  4. Verify the Swift version

    Once reinstalled, you should verify the version of Swift to ensure it's aligned with the correct SDK:

    swift --version
    

  5. 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.modulemap and /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.backup
    

    Then, check if Swift works again after that.

  6. 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-path
    

    If the path seems wrong or outdated, you can try resetting it with:

    sudo xcode-select --reset
    
  7. Check for Conflicting Environment Variables

    There might be environment variables that are causing conflicts, like SDKROOT or DEVELOPER_DIR. Try clearing them or setting them explicitly:

    unset SDKROOT
    unset DEVELOPER_DIR
    

Installing Swift on Ubuntu 20.04

  1. 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
    

  2. Download Swift Get the URL for the latest version here: https://www.swift.org/download/

    wget https://download.swift.org/swift-5.8.1-release/ubuntu2204/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-ubuntu22.04.tar.gz
    
    Untar
    tar xzf swift-5.8.1-RELEASE-ubuntu20.04.tar.gz
    

  3. Move files

    sudo mv swift-5.8.1-RELEASE-ubuntu20.04 /usr/share/swift
    

  4. Add to system PATH enviroment variable

    echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.zshrc
    
    source ~/.zshrc
    

    echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bash_profile
    
    source ~/.bash_profile
    

  5. 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
Then run it like so, with arguments:
tasks run bar