Skip to content
swift: command not found

swift: command not found

DodaTech 2 min read

The “swift: command not found” error means your shell cannot locate the Swift compiler binary. This prevents you from compiling or running Swift code from the command line.

What It Means

Swift’s command-line tools include the swift compiler, the swiftc compiler for producing binaries, and the Swift package manager (swift package). When the shell cannot find the swift binary in any directory listed in your PATH variable, it returns “command not found.”

Why It Happens

  • Xcode is not installed on macOS — Xcode includes the Swift toolchain.
  • Xcode command-line tools are missing — xcode-select --install has not been run.
  • Swift toolchain is installed on Linux but not added to PATH.
  • The toolchain directory (e.g., /usr/bin) does not contain the Swift binaries.
  • You installed Swift via a package manager but the binary is located in a non-standard path.
  • The installed Swift version does not match your OS architecture.

How to Fix It

1. Install Xcode (macOS)

# Install Xcode from the Mac App Store, then install command-line tools
xcode-select --install

2. Install Swift on Linux

Ubuntu / Debian:

# Download the Swift toolchain for your Ubuntu version from swift.org
wget https://download.swift.org/swift-5.10-release/ubuntu2204/swift-5.10-RELEASE/swift-5.10-RELEASE-ubuntu22.04.tar.gz
tar xzf swift-5.10-RELEASE-ubuntu22.04.tar.gz
sudo mv swift-5.10-RELEASE-ubuntu22.04 /usr/share/swift

3. Add Swift to your PATH

Linux: Add this to ~/.bashrc or ~/.zshrc:

export PATH="$PATH:/usr/share/swift/usr/bin"
source ~/.bashrc

4. Verify the installation

swift --version
# Output: Swift version 5.10 (swift-5.10-RELEASE)

5. Set the Xcode toolchain (macOS, multiple Xcode versions)

# List available toolchains
xcrun swift --version

# Select the active developer directory
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Can I use Swift without Xcode on macOS?
Yes — install only the command-line developer tools with xcode-select --install. This provides swift, swiftc, and related tools without the full Xcode IDE.
What if Swift is installed but still not found?
Run which swift or find / -name swift -type f 2>/dev/null to locate the binary. Then add its directory to your PATH.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro