Golang environment construction [goenv]

What is goenv

goenv is Go's version control version control tool.

install goenv

For Homebrew

$ brew install goenv

For git goenv installation

$ git clone https://github.com/syndbg/goenv.git ~/.goenv

PATH goenv

Describe the path in the configuration file. (Description in the shell you are using)

$ echo 'export GOENV_ROOT="$HOME/.goenv"' >> ~/.zshrc
$ echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(goenv init -)"' >> ~/.zshrc

$ source ~/.zshrc   //Update changes
$ goenv -v
goenv 2.0.0beta11

If you can confirm the version, you are done.

Install Go

Display a list of versions that can be installed with the following command

$ goenv install -l
1.2.2
  1.3.0
  1.3.1
  〜
  1.15rc2
  1.15.1
  1.15.2

Install any version.

$ goenv install 1.**.*

Go PATH

~/.zshrc


$ echo 'export PATH="$GOROOT/bin:$PATH"' >> ~/.zshrc
$ echo 'export PATH="$PATH:$GOPATH/bin"' >> ~/.zshrc

$ source ~/.zshrc

Select the version to use

Set the installed version to global. Also, switching to a version.

$goenv global 1.**.*
$ go version
go version go1.**.* darwin/amd64

If you can confirm the version, you are done.

VS Code environment construction

First, install the Go plugin. スクリーンショット 2020-10-17 17.06.37.png

Tool installation

Next, we will install useful tools. First, open the settings and search for go.use language server to see if it is checked. After checking, open the display of all commands with `shift + ⌘ + P```, type Go: Install / Update Tools , and then gocode``` and `` gocode- Select and install other than gomod``` (since the code completion function is performed by gopls). If you don't see gopls here, try typing gopls in the search tab. スクリーンショット 2020-10-17 17.21.52.png

Optional settings.json settings

After installation, add the following to settings.json.

settings.json


"go.useLanguageServer": true,
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
        "editor.snippetSuggestions": "none"
    },
    "gopls": {
        "hoverKind": "SynopsisDocumentation",
        "usePlaceholders": true,
        "linkTarget": "pkg.go.dev",
        "staticcheck": false,        
        "completionDocumentation": true,        
        "completeUnimported": true,        
        "deepCompletion": true
    },
    "files.autoSave": "afterDelay"

that's all!

Recommended Posts

Golang environment construction [goenv]
Golang environment construction
Django environment construction
DeepIE3D environment construction
Emacs-based environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
python environment construction
Word2vec environment construction
Environment construction: GCP + Docker
Django project environment construction
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
pyenv + fish environment construction
python2.7 development environment construction
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Anaconda environment construction memo
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
About Linux environment construction (CentOS)
PyTorch C ++ (LibTorch) environment construction
Django development environment construction memo
First LAMP environment construction (Linux)
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
ML environment construction with Miniconda
Python environment construction For Mac
Anaconda3 python environment construction procedure
Docker + Django + React environment construction
Python3 environment construction (for beginners)
NumPy and matplotlib environment construction
Machine learning environment construction macbook 2021
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
Environment construction, Build -Go edition-
django project development environment construction
Linux environment construction (on WSL environment)
Environment construction of python2 & 3 (OSX)
[MEMO] [Development environment construction] wine
Ansible environment construction For Mac
Golang + Gin + Docker hot reload, VS Code debugging environment construction
DL Laravel environment construction method (Linux)
Environment construction of python and opencv
Mac + Eclipse (PyDev) + Django environment construction