Fixing Go Command Not Found on macOS | Generated by AI

Home PDF

The error message /bin/sh: go: command not found indicates that the Go programming language is not installed on your macOS system, or it’s not properly configured in your PATH. The make command is trying to run a Go build process, which requires the Go compiler (go). Below are the steps to install Go on macOS and resolve this issue.

Steps to Install Go on macOS

There are two primary ways to install Go on macOS: using the official Go installer or using Homebrew. I’ll cover both methods, but Homebrew is often simpler for macOS users. Choose one method based on your preference.

Prerequisites

Homebrew is a popular package manager for macOS that simplifies software installation.

  1. Install Homebrew (if not already installed):
    • Open Terminal and run:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
    • Follow the on-screen instructions to complete the installation.
  2. Install Go:
    • Run the following command to install the latest version of Go:
      brew install go
      
    • This installs Go to /usr/local/Cellar/go (or a similar path) and adds the Go binary to /usr/local/bin.
  3. Verify Installation:
    • Check the installed Go version by running:
      go version
      
    • You should see output like go version go1.23.x darwin/amd64, confirming Go is installed.
  4. Set Up Environment Variables (if needed):
    • Homebrew typically adds Go to your PATH automatically, but if go commands don’t work, add the Go binary path to your shell profile:
      • Open or create the appropriate shell configuration file (e.g., ~/.zshrc for Zsh, which is default on macOS since Catalina, or ~/.bash_profile for Bash):
        nano ~/.zshrc
        
      • Add the following lines:
        export PATH=$PATH:/usr/local/go/bin
        
      • Save the file (Ctrl+X, then Y, then Enter in nano) and apply the changes:
        source ~/.zshrc
        
      • If you want to use a custom workspace, set GOPATH (optional, as Go modules often eliminate the need for this):
        export GOPATH=$HOME/go
        export PATH=$PATH:$GOPATH/bin
        
      • Source the file again:
        source ~/.zshrc
        
  5. Test Go Installation:
    • Run go version again to ensure the command is recognized.
    • Optionally, create a simple Go program to confirm everything works:
      mkdir -p ~/go/src/hello
      nano ~/go/src/hello/main.go
      
      • Add the following code:
        package main
        import "fmt"
        func main() {
            fmt.Println("Hello, World!")
        }
        
      • Save and exit (Ctrl+X, Y, Enter), then compile and run:
        cd ~/go/src/hello
        go run main.go
        
      • You should see Hello, World! as output.

Method 2: Install Go Using the Official Installer

If you prefer not to use Homebrew, you can install Go using the official macOS package.

  1. Download the Go Installer:
    • Visit the official Go download page: https://go.dev/dl/
    • Download the macOS package (.pkg) for your system architecture (e.g., go1.23.x.darwin-amd64.pkg for Intel Macs or go1.23.x.darwin-arm64.pkg for Apple Silicon).
  2. Run the Installer:
    • Double-click the downloaded .pkg file in Finder.
    • Follow the on-screen instructions to install Go. It will be installed to /usr/local/go by default.
    • You may need to enter your administrator password.
  3. Set Up Environment Variables:
    • Open Terminal and edit your shell configuration file (e.g., ~/.zshrc or ~/.bash_profile):
      nano ~/.zshrc
      
    • Add the following lines:
      export GOROOT=/usr/local/go
      export GOPATH=$HOME/go
      export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
      
    • Save and apply the changes:
      source ~/.zshrc
      
    • Note: GOROOT is optional unless you’re developing Go itself or need a non-standard installation path. Modern Go versions often don’t require GOROOT to be set.
  4. Verify Installation:
    • Run:
      go version
      
    • You should see the installed Go version (e.g., go version go1.23.x darwin/amd64).
  5. Test Go Installation:
    • Follow the same steps as in Method 1, Step 5 to create and run a “Hello, World!” program.

Troubleshooting the Original Issue

After installing Go, navigate back to your clash-core directory and retry the make command:

cd /path/to/clash-core
make

If you encounter issues:

Additional Notes

Verification

Once Go is installed and the make command succeeds, the clash-core binary should appear in the bin/ directory (e.g., bin/clash-linux-amd64 or bin/clash-darwin-amd64). Verify it works by running:

./bin/clash-darwin-amd64 --version

If you need further assistance or run into specific errors, let me know the exact error message or context, and I can provide more targeted help!


Back 2025.06.28 Donate