- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How To Install Go (Golang) 1.7 on CentOS 7
In this article, we will learn about how to install and configure Go (golang) which is developed by Google and its open source programming language. It’s a simple, efficient and reliable programming language for development with minimalist.
Prerequisites
- A CentOS machine installed.
- A non-root user with Sudo permission on the CentOS machine.
Downloading and Installing the GO
The Go (golang) is not up to date on the CentOS repository, so we will manually download and install the package directly from the Go lang website and also make sure that we have the latest version which is compatible with our system architecture.
Let’s move to the writable and temporary directory where we can download the package from the Go website and install.
$ cd /tmp
We will use the curl command to download the Go with the below link
$ curl -LO https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 84 77.7M 84 65.5M 0 0 493k 0 0:02:41 0:02:15 0:00:26 0 curl: (56) TCP connection reset by peer
Once the package is downloaded from the site, we will extract the package to /usr/local and install the package.
Below is the command to extract the package to /usr/local
$ tar -C /usr/local/ -xvf go1.7.linux-amd64.tar.gz
Once the packages are extracted in /usr/local we needed to create a workspace with three sub-directories, we consider the parent directory as ~/myproject, below is the command to create the three sub-directories.
$ mkdir –p ~/myproject/{bin,pkg,src}
Setting Up The Environment Variables for the Go
If we want to execute the Go like the other command we needed to all the paths to the $PATH variables for that we needed to create a file path.sh to /etc/profile.d folder using any text editor
$ sudo nano /etc/profiled/path.sh Export PATH=$PATH:/usr/local/go/bin
We have to define the GOPATH and GOBIN which are GO environment variable on the .bash_profile for pointing the workspace. Where are GOPATH will show the location of the source files and GOBIN will stores the binary files which are created and is compiled.
Edit the .bash_profile with any of your choice editor using the below command
$ nano ~/.bash_profile export GOBIN="$HOME/myprojects/bin" export GOPATH="$HOME/myprojects/src"
To apply the changes made in the .bash_profile we needed to run the below command
$ source /etc/profile && source ~/.bash_profile
Creating a Simple Go Program
As the Go (golang) environment is ready, we needed to test our environment, we will write one simple Go program.
$ nano ~/myprojects/src/welcome.go
Below is the code which will print Welcome to the Go (golang) .
Package main Import “fmt” Func main() { Fmt.Printf(“Welcome to the Go (golang) \n “) }
As we have written a simple code for testing the Go environment, we have to compile the ‘welcome.go’ with go install command, bellow is the full command to compile the file.
$ go install $GOPATH/welcome.go
Once the program is compiled, we can test the program with the below command –
$ $GOBIN/welcome Welcome to the Go (golang)
In the above article we have learned how to install the Go (golang) programming language which is from Google and we have written a simple program and executed to test the environment to confirm the installation is successful.
- Related Articles
- How to install graylog 1 3graylog2 on centos 7rhel 7
- How to install docker on centos 7
- How to Install and Configure Ansible on CentOS 7
- How To Install and Configure MongoDB on CentOS 7
- How to install install mariadb 10 2 centos 7
- How to install and configure prometheus using docker on centos 7
- How to install and use docker and containers on centos 7
- How to Install and Configure MS SQL (Beta) on CentOS 7
- How to install and configure puppet with master agent on centos 7
- How to install and configure dropbox as a service on centos 7
- How to install and configure own wordpress instance on linux centos 7
- How to install gnome desktop on centos rhel 7 using yum command
- How to install and configuration ftp server in centos 7
- How to install the latest version of Git on CentOS 7.x/6.x?
- How To Use Systemctl On CentOS 7.x or RHEL Linux 7
