About the Go language environment configuration sdk+path+ working directory

Source: Internet
Author: User

First step: Install the SDK for Golang

http://golang.org, download the latest installation package, and then double-click Install.

After the installation is complete, open the terminal, enter go, or go version (view the installation version) the following information appears to indicate that the installation was successful:

$ go Versiongo version go1.5.1darwin/amd64

Note here:

Install under Linux

We take Ubuntu 64 as an example, and other Linux distributions like CentOS are similar.

After downloading go1.9.linux-amd64.tar.gz, unzip, you can use your own decompression software decompression, if not can be extracted in the terminal line using the TAR command line tool, we choose the installation directory here is /usr/local/go , can be used the following command:

1 Tar-c/usr/local-xzf go1.9.linux-amd64.tar.gz

If the prompt does not have permission, precede it sudo with the root user. After running, /usr/local/ you can see the go directory below. If you use the software to extract, you can copy to/usr/local/go, but to ensure that your Go folder is bin, SRC, doc and other directories, not go folder is a Go folder, so double nested.

Then you have to configure the environment variables, Linux and two files can be configured, which /etc/profile is valid for all users $HOME/.profile , is valid for the current user, you can choose according to their own circumstances.

Restart the computer for all users to take effect, and for the current user, use the source command in the terminal to load this to $HOME/.profile take effect.

1 SOURCE ~/.profile

Using a text editor such as vim to edit any of them, add the following configuration at the end of the file to save it:

12 export goroot=/usr/local/go Export path=$PATH:$GOROOT/bin

Where the GOROOT environment variable represents our go install directory, so that other software such as our use of the go Development IDE can automatically find our go installation directory, to automatically configure the Go SDK.

The second sentence configuration is to /usr/local/go/bin add this directory to the environment variable path, so I can in the terminal directly input go and other common commands used, and do not add /usr/local/go/bin this string absolute path, more concise and convenient.

After the above configuration, we open the terminal, the following command, you can see the version of Go and other information.

12 ? ~ Go Versiongo version go1.9 linux/amd64

This means that we have installed go successfully, if prompted to go this command can not be found, indicating that we are not configured, mainly in the path of the environment variable, carefully check until it can output normally.

Install under Mac

Mac is divided into compressed version and installation version, they are all 64-bit. The compact version and Linux are much the same, because both Mac and Linux are UNIX-based, the end of this piece is basically the same.

Compressed version of the decompression, it can be placed in the same directory as Linux, and here also /usr/local/go/ for example. When configuring environment variables, it is the same for all users and Linux, and for the /etc/profile current user, the Mac is the $HOME/.bash_profile same as other configurations, including the ability to edit sudo permissions and how to take effect, and finally test in the terminal:

12 ? ~ Go Versiongo version go1.9 darwin/amd64

After downloading the MAC installation version, double-click to see the installation interface, follow the prompts to select the action step. The installation version of the default installation directory is /usr/local/go , and will automatically /usr/local/go/bin add the directory to the PATH environment variable, re-open a terminal, you can use go version to test, more quickly and conveniently.

Install under Windows

Windows also has a compressed and installed version, and is divided into 32 and 64 bits to choose from, but at present everyone is 64 bit, choose this better.

Window compression version is a ZIP compression package, after downloading the use of WinRAR and other software can be extracted, decompression to choose a storage directory, such as the c:\Go next, this c:\Go is the installation directory of Go, he has bin, SRC, doc and other directories.

Then is the environment variable configuration, window and Linux as a system variable for all users, and for the current user user variable settings, you can choose, such as system variables, for all users are valid.

Take window 7 as an example, right-click My Computer----the properties will open the System Control Panel, and then on the left to find the 高级系统设置 click to open, the screen will appear at the bottom of the popup 环境变量 button, click on it, you can see the environment variable configuration interface. The upper part is the user variable configuration, and the lower half is the system variable configuration.

We click New in the system variables, variable name input goroot, the variable value is the Go path we just installed c:\Go , so that the Go Directory installation path is configured.

Then modify the path system variable, add the path in the value of the variable, %%GOROOT\bin and the other path variable, (semicolon, a colon under Linux) to split. So we can just enter the Go command in CMD and use it.

Open our terminal, enter the go version test, then you can see the output of the information.

Window installation version is relatively simple, double-click can follow the prompts to install, the default installation path is c:\Go , and will configure the PATH environment variable, you can directly open the CMD terminal use.



Here are the settings for the working directory:

Set up working directory

The working directory is where we use the source code for the development, which is also the GOPATH environment variable in go. After this environment variable is specified, we compile the source code and other generated files will be placed in this directory, the configuration of the Gopath environment variable refer to the above installation go, configured to /etc/profile or under Windows system variables.

This working directory can be specified according to our own settings, such as my Mac under $home/code/go, window can be placed in the d:\code\go inferior. There are 3 subdirectories under this directory, respectively:

1234 . ├──bin├──pkg└──src
    • The Bin folder holds the go install named generated executable file, and you can add the $gopath/bin path to the PATH environment variable, just like the $goroot/bin we configured above, so that we can use our Go development generated program directly in the terminal.
    • The Pkg folder is a file that has a go compilation build.
    • SRC stores our Go source code, and the code for different projects is differentiated by package name.



About the Go language environment configuration sdk+path+ working directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.