BryanWheelock
BryanWheelock

Reputation: 12244

Why can't I run the go binary from within the /bin directory?

I downloaded go1.7.5.darwin-amd64.tar.gz for osx 10.12.2.

Unpacked the tar and went to the /bin directory to see if the Go executable would run.

$ cd Downloads/go/bin 
$ ls

total 54560  
-rwxr-xr-x@ 1 bryanwheelock  staff   9884220 Feb 10 16:53 go  
-rwxr-xr-x@ 1 bryanwheelock  staff  15065500 Feb 10 16:53 godoc  
-rwxr-xr-x@ 1 bryanwheelock  staff   2976976 Feb 10 16:53 gofmt  

bryanwheelock@Bryans-MacBook Fri Feb 10 16:57:45 ~/Downloads/go/bin
$ go version
-bash: go: command not found

Upvotes: 0

Views: 2226

Answers (2)

Jeyem
Jeyem

Reputation: 310

sudo chmod +x go

seems like it does not have execute permission, so just change permission and run it then you should alias your go binary path to your environment to access binary every where.

Upvotes: -1

Koala Yeung
Koala Yeung

Reputation: 7843

When you type a command without giving the full path, your system will try to find it within all the folders provided in $PATH variable.

In typical Unix environment, your $PATH does not include "your current folder". So you need to either:

  • call go by its full path (i.e. $HOME/Downloads/go/bin/go); or
  • call go by its relative path (i.e. ./go); or
  • put $HOME/Downloads/go/bin in your $PATH variable; or
  • put . (Unix way of saying "your current folder") in your $PATH; or
  • put your go binary into folders that already in your $PATH. For example

    sudo cp $HOME/Downloads/go/bin/* /usr/local/bin/.
    

Upvotes: 3

Related Questions