Describes the procedure to install ** Go ** (Go language) on ** macOS **. I used Go's version control tool ** goenv ** to install Go. I also use ** Homebrew ** to install goenv. I stumbled on the part that passes through the PATH, so the explanation there is also described in the latter half.
If you have not installed Homebrew, please install it from this Official.
$ brew update
$ brew install goenv
If the version is displayed with the following command, it is complete.
$ goenv -v
$ goenv install -l
Install Go by specifying the version. (1.11.4 is specified in this article)
$ goenv install 1.11.4
Check the Go installed on your machine.
$ goenv versions
When you execute the command, the following output will be displayed in the terminal. The version with * (asterisk) is the version currently in use.
system
* 1.11.4 (set by /Users/[User name]/.goenv/version)
Installation is completed at this point.
After installing with the above procedure, when the go command is executed, the following error occurs.
bash: go: command not found
According to the content of the error, it seems that the cause is that the PATH does not pass, so set the PATH. First, check the directory where Go is installed.
However, I couldn't find the directory because I installed it with goenv. After all, I searched the directory that was output when the following command was executed and found the installation destination directory.
$ goenv version
1.11.4 (set by /Users/[User name]/.goenv/version)
The directory that was actually installed is as follows.
/Users/[User name]/.goenv/versions/1.11.4/
Open .bash_profile
(configuration file) with vim.
$ vim ~/.bash_profile
Add the following to .bash_profile
.
export GOROOT=$HOME/.goenv/versions/1.11.4
export PATH=$GOROOT/bin:$PATH
Reflect changes in .bash_profile
.
$ source ~/.bash_profile
When the Go version is displayed, it's done.
$ go version
go version go1.11.4 darwin/amd64
Recommended Posts