[MacOS] Installation of Go (Go language) using goenv

Overview

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.

[Reference] Official

Execution environment

Installation procedure

1. Update Homebrew.

If you have not installed Homebrew, please install it from this Official.

$ brew update

2. Install goenv

$ brew install goenv

If the version is displayed with the following command, it is complete.

$ goenv -v

3. Check the version of GO language that can be used

$ 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.

Stumble 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/

PATH setting

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

[MacOS] Installation of Go (Go language) using goenv
Installation of psutil fails on MacOS Cataline
What Java users thought of using the Go language for a day
Installation of Anaconda3
Installation of CentOS 8
Hello world with full features of Go language
Pretty print of ML language using parser combinator
100 language processing knock-75 (using scikit-learn): weight of features
Python installation 2020 (macOS)
100 Language Processing Knock-36 (using pandas): Frequency of word occurrence
Perform multiple version control of Go with anyenv + goenv
Ruby expert learned the basic grammar of Go language
Go language learning record
Go language environment construction
Introduction of ferenOS 1 (installation)
[Linux] Installation of nvm
Installation of Python 3.3 rc1
Go language cheat sheet
Example of using lambda
Installation of matplotlib (Python 3.3.2)
Installation of dlib, cv2
[Go language] Collect and save Vtuber images using Twitter API
[Golang] Basics of Go language About value receiver and pointer receiver