Reputation: 998
In Go compiler, when I do "go run", executable file is stored to a temporary location. How to change this path to store the file in current working directory? I am using windows 7 64bit machine.
Upvotes: 4
Views: 5765
Reputation: 7586
The folder used by Go to store the temporary executable can be changed by setting the GOTMPDIR environment variable.
More info here: https://stackoverflow.com/a/71197493/1057961
Upvotes: 5
Reputation: 21957
Agree with previous answers. go install
saves binary file into GOBIN
folder. So you may change it to have a specific location. However, I don't suggest to do it, because you can always build into specific folder using -o
option of go build
:
go build -o /usr/bin/app main.go
Upvotes: 2
Reputation: 40759
I agree with @Adrian and @Saleem, however, for interest sake, you can override the location (somewhat) by changing the location of your environment variable TEMP
(or TMPDIR
on OSX or Linux). This will still create a temporary directory in whatever directory you specify, in which the working files will be placed. Keep in mind that as Adrian and Saleem say, go run
is intended for temporary runs.
And of course @JimB beat me to it with his comment which is really the essence of what I'm saying here.
Upvotes: 2
Reputation: 46433
If you want to do something with the binary beyond just running it once, you should be using go build
, not go run
. go build
will put the binary in the current working directory.
Upvotes: 9