官术网_书友最值得收藏!

Setting up the environment

In order to get started with Echo, you will need a working Go environment. To that end, installing Go in your environment is fairly trivial. Firstly, we need to download the Go source code and tool chain and install them. For this book, we will be using Go version 1.9.4, which is the latest release at the time of writing this book. As you can see at https://golang.org/doc/install, there are detailed instructions for setting up your environment correctly. The following are the typical steps needed to install Go for your system:

Linux/macOSX Go Installation

Download Go 1.9.4:

  • Linux:
      curl -O https://dl.google.com/go/go1.10.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
  • macOS using Homebrew:
      brew install go

Set up related environmental variables (assuming you use bash):

mkdir -p ~/go

echo "export GOPATH=$HOME/go" >> ~/.bashrc

echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc

source ~/.bashrc

At this point, the environment is set up. The preceding curl command downloads Go as a tarball, and the tar command will unpack the Go standard library source code and related binary tools into the /usr/local/go directory on your system. If you are running this as a non-root user, you might need to run the tar command listed in the preceding snippet with root privileges, potentially by changing users to root, or running the command with sudo.

The preceding environment variable setup commands will first set up a workspace as a go directory within your home directory. The command will also set your GOPATH environment variable to use this workspace for downloading go packages. Next, we need to set the PATH variable to include the bin directory that was installed in /usr/local/go/which is where the Go compiler, as well as other tools such as gofmt that come with Go, reside. Finally, we add all of these environment variables into your .bashrc so that every time you log in, these environment variables are set appropriately.

Windows installation

You can download the MSI installer for Go: https://dl.google.com/go/go1.10.windows-amd64.msi.

The Windows installer will, by default, install Go in the c:\Go\ folder. The installer will take care of setting up all necessary environment variables for you.

主站蜘蛛池模板: 通州区| 大宁县| 普陀区| 芦山县| 浦北县| 祁连县| 巴楚县| 尉氏县| 邵东县| 正阳县| 凤城市| 晴隆县| 乐平市| 麦盖提县| 专栏| 托克逊县| 安福县| 温宿县| 峨眉山市| 鹰潭市| 永德县| 福安市| 绍兴市| 亚东县| 九台市| 银川市| 高平市| 汝阳县| 雷州市| 沧源| 文水县| 平阴县| 衡阳县| 沙坪坝区| 乌拉特前旗| 平凉市| 台中市| 靖江市| 宿松县| 连云港市| 兴化市|