Reputation: 6844
I'm trying to run Go
in an interactive mode.
I want to use go-eval
for that, I followed their README
instructions:
go get github.com/sbinet/go-eval/
successfullygo-eval
which resulted in -bash: go-eval: command not found
Some more information:
echo $PATH
returns: /usr/local/go/bin:...
echo $GOPATH
returns: $HOME/golang
running whereis go-eval
returns no output
running go install go-eval
returns:
can't load package: package go-eval: cannot find package "go-eval" in any of:
/usr/local/go/src/go-eval (from $GOROOT)
$HOME/golang/src/go-eval (from $GOPATH)
Upvotes: 64
Views: 83962
Reputation: 590
add those line in to ~/.zshrc
export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin
run source ~/.zshrc
Upvotes: 18
Reputation: 3044
You'll need to add GOPATH/bin
to PATH
.
PATH="$GOPATH/bin:$PATH"
Update [Go 1.8 and above]: GOPATH
will default to $HOME/go
. The above will not work if GOPATH
is not explicitly set.
To set both, add this to your .profile
file:
export GOPATH="$HOME/go"
PATH="$GOPATH/bin:$PATH"
Upvotes: 161
Reputation: 51
Ran into this issue while using export PATH="~/go/bin:$PATH"
.
Seems the ~
was causing problems and changing to the full path worked.
Try something like this instead, which won't use a tilde:
export PATH="$HOME/go/bin:$PATH"
Upvotes: 5
Reputation: 561
All above answers are self explaining. Over and above those I would like to add that by default you can access only those commands from terminal without path to binary whose bin
folder is added to the environment variable, be it linux, mac or windows.
Else you will have to specify the path to bin folder of that software followed by the binary name. For instance in your case <path_to_bin_folder>/go-eval
.
This is the most common reason that you are not able to execute that command directly from the command line. Please remember this and try this before searching for answers online because this will most probably solve your issue. All you have to know is the installation path.
So, write the following into the rc
or profile
file for your terminal and save, example for zsh it is ~/.zshrc
, for bash it is ~/.bash_profile
or ~/.bash_rc
.
export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin
Now although the file is saved but the changes will not reflect immediately. You have to source the profile file as mentioned above. For this type source ~/.zshrc
. You should now be able to run the command directly from command line now. Even if the problem still persists try quit the terminal session and logging off and then logging in.
In case you want to add path to bin folder for other packages, you can append it to the $PATH environment variable using :
. So for example if you want to add path to java binary as well, then just do
export PATH=$PATH:$JAVA_HOME/bin
Also it is a good practice to define the path to root folder of a package in its separate environment variable(example $GOPATH="$HOME/go"
). In case if the installation path changes in future then you'll just have to update the environment variable related to that binary (example just update, $GOPATH="newpath") and your command will work as previously, since the change in $GOPATH will reflect in $PATH.
Upvotes: 2
Reputation: 273
I'd like to add this in addition to the answers given.
As a helpful tip, uou can always test your commands with the which command.
Such as: which go
If the command is not found, you know you have a PATH problem you need to address first.
Then you can focus on finding the command with the find command.
Such as: find / -name "go" -print 2>/dev/null
The first slash is the directory to start the search, the argument to the -name is the command you're looking for and the -print gets a good results look. the 2>/dev/null sends results of directories that are not accessible to neverland (null) so that you do not need to see a bunch of errors.
Using this process helps you quickly find the command in question and then you can add it to your PATH env variable and it becomes accessible as stated in the other answers.
Upvotes: 3
Reputation: 1483
Is the binary go-eval
in $GOPATH/bin
? Are you running the command with $GOPATH/bin/
as your working directory? If not, thats likely the problem.
go get
& go install
installs go binaries (if any) in $GOPATH/bin
Check $GOPATH/bin
for the go-eval binary. If its there, try running it from $GOPATH/bin
with ./go-eval
. If that works, you're good.
In future, if you wish to run go binaries found in $GOPATH/bin
from anywhere in your shell, add the following to your .bashrc or profile:
export PATH=$PATH:$GOPATH/bin
Then restart your terminal or run . ~/.bashrc
or . /etc/profile
When running go install go-eval I get:
can't load package: package go-eval: cannot find package "go-eval" in any of: /usr/local/go/src/go-eval (from $GOROOT) $HOME/golang/src/go-eval (from $GOPATH)
You get the above error because go-eval is not in $HOME/golang/src/go-eval
. Running go get github.com/sbinet/go-eval/
will download the source to $GOPATH/src/github/sbinet/go-eval/
. If you want to run go install go-eval
, you have to specify the package name relevant to its position in the directory hierarchy in $GOPATH/src
.
e.g.
go install github/sbinet/go-eval
Upvotes: 6