If I had a compiled Golang program that I wanted to install such that I could run it with a bash command from anywhere on my computer, how would I do that? For example, in nodejs
npm install -g express
Installs express such that I can run the command
express myapp
and express will generate a file directory for a node application called "myapp" in whatever my current directory is. Is there an equivalent command for go? I believe now with the "go install" command you have to be in the directory that contains the executable in order to run it
Thanks in advance!
As far as I know, there is no direct equivalent to
npm install -g
. The closest equivalent would not bego install
, butgo get
. From the help page (go help get
):By default,
go get
installs binaries to$GOPATH/bin
, so the easiest way to make those binaries callable from everywhere is to add that directory to your$PATH
.For this, put the following line into your
.bashrc
(or.zshrc
, depending on which shell you're using):Alternatively, you could also copy or link the executables to
/usr/local/bin
: