Go Install
go install
- When you run the above command, Go will compile the program and installs a binary in the bin location. For mac it is created at '/usr/local/go/bin/trygo' by default.
Steps:
- Move to your project folder using "cd projects/go/src/trygo"
- Run 'go install'
- You can execute the binary using '~/projects/go/bin/trygo'
- Run 'go install'
- You can execute the binary using '~/projects/go/bin/trygo'
Possible issues:
- Ran into the following issue when i ran the above command
go install trygo: open /usr/local/go/bin/trygo: permission denied
- I fixed it by changing the 'GOBIN' path in bashrc
export GOBIN=~/projects/go/bin
export PATH=$PATH:$GOBIN
Go Build
go build
- 'go build' is similar to 'go install' the only difference is it creates the binary inside the location you ran 'go build'
- To run the program you can just say 'trygo/trygo' (The first trygo is the location for the binary and trygo is the binary file generated by Go compiler)
- To run the program you can just say 'trygo/trygo' (The first trygo is the location for the binary and trygo is the binary file generated by Go compiler)
Go Run
go run main.go
- One more way of running go program is using 'go run <--filename.go-->'
- 'go run' works very similar to 'go build/ go install' however instead of installing the program binary into 'GOBIN' or current directory, it compiles the file to a temporary location and runs from that location.
- So where is that temp location??? use the following command to find out
Happy coding 👨💻
- 'go run' works very similar to 'go build/ go install' however instead of installing the program binary into 'GOBIN' or current directory, it compiles the file to a temporary location and runs from that location.
- So where is that temp location??? use the following command to find out
go run --work main.go
Happy coding 👨💻
Comments
Post a Comment