How To Install Go on Digital Ocean with a CentOS7 Droplet

I will mostly be following the instructions from here, but instead of Ubuntu I am going to try CentOS.

Getting Started

All you will need to start, aside from the obvious internet connection, is a Digital Ocean account. I’ve found that the $5/mo. plan is really good for learning.

Spin up your droplet

This is actually pretty straightforward. Your regional preferences may differ, but here are what my settings looked like:

You’ll immediately see a progress bar to show you how quickly the droplet is being started:

Actually, it took less than 60 seconds total to completely spin that up. This is my first experience with Digital Ocean, so I’m pretty impressed with that.

Once the droplet is up and running, you will receive an email similar to this one, that will include your login credentials:

Yes, that is Google Inbox. It’s shiny, right?

Use these to SSH into your new droplet:

$ ssh digital-ocean
The authenticity of host '[address] ([address])' can't be established.
RSA key fingerprint is [key].
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[address]' (RSA) to the list of known hosts.
[email protected][address]'s password:
You are required to change your password immediately (root enforced)
Changing password for root.
(current) UNIX password:
New password:
Retype new password:
[[email protected] ~]#

(Note that I updated my ~/.ssh/config file to include the hostname and user name for this droplet and provided it the alias digital-ocean. If you do not do this, then you can simply SSH into the address provided in the credentials email.)

Create a new user

According to the Ubuntu instructions provided, the next step is to create a new user account. Pretty straightforward, but since the commands are a little different for CentOS7, I am using Digital Ocean’s Initial Server Setup with CentOS 7 instructions. Here I am creating a new user, providing that user with superuser privileges, and changing accounts into the new user account:

[[email protected] ~]# adduser quinn
[[email protected] ~]# passwd quinn
Changing password for user quinn.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]# gpasswd -a quinn wheel
Adding user quinn to group wheel
[[email protected] ~]# su quinn
[[email protected] root]$

To create your own user, simply replace quinn with your desired username.

Installing Go

The Ubuntu instructions use apt-get for this, but CentOS does not have apt-get available. But we’re in luck! We can just run sudo yum install golang (or run the command as root) to install the latest release of Go (yes, there is a lot of output):

[[email protected] root]$ sudo yum install golang
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
[sudo] password for quinn:
Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/4): extras/7/x86_64/primary_db                          |  35 kB   00:00
(2/4): base/7/x86_64/group_gz                              | 157 kB   00:00
(3/4): updates/7/x86_64/primary_db                         | 4.8 MB   00:01
(4/4): base/7/x86_64/primary_db                            | 4.9 MB   00:01
Determining fastest mirrors
 * base: mirror.ash.fastserv.com
 * extras: mirrors.advancedhosters.com
 * updates: mirrors.lga7.us.voxel.net
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.3.3-1.el7.centos will be installed
--> Processing Dependency: golang-src for package: golang-1.3.3-1.el7.centos.x86_64
--> Processing Dependency: golang-bin for package: golang-1.3.3-1.el7.centos.x86_64
--> Running transaction check
---> Package golang-pkg-bin-linux-amd64.x86_64 0:1.3.3-1.el7.centos will be installed
--> Processing Dependency: golang-pkg-linux-amd64 = 1.3.3-1.el7.centos for package: golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_64
--> Processing Dependency: golang-pkg-linux-amd64 = 1.3.3-1.el7.centos for package: golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_64
--> Processing Dependency: gcc for package: golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_64
---> Package golang-src.noarch 0:1.3.3-1.el7.centos will be installed
--> Running transaction check
---> Package gcc.x86_64 0:4.8.2-16.2.el7_0 will be installed
--> Processing Dependency: cpp = 4.8.2-16.2.el7_0 for package: gcc-4.8.2-16.2.el7_0.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.2-16.2.el7_0.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.2-16.2.el7_0.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.2-16.2.el7_0.x86_64
---> Package golang-pkg-linux-amd64.noarch 0:1.3.3-1.el7.centos will be installed
--> Running transaction check
---> Package cpp.x86_64 0:4.8.2-16.2.el7_0 will be installed
---> Package glibc-devel.x86_64 0:2.17-55.el7_0.1 will be installed
--> Processing Dependency: glibc-headers = 2.17-55.el7_0.1 for package: glibc-devel-2.17-55.el7_0.1.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-55.el7_0.1.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-55.el7_0.1 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-55.el7_0.1.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-55.el7_0.1.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-123.9.3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package                       Arch      Version               Repository  Size
================================================================================
Installing:
 golang                        x86_64    1.3.3-1.el7.centos    extras     2.6 M
Installing for dependencies:
 cpp                           x86_64    4.8.2-16.2.el7_0      updates    5.9 M
 gcc                           x86_64    4.8.2-16.2.el7_0      updates     16 M
 glibc-devel                   x86_64    2.17-55.el7_0.1       updates    1.0 M
 glibc-headers                 x86_64    2.17-55.el7_0.1       updates    650 k
 golang-pkg-bin-linux-amd64    x86_64    1.3.3-1.el7.centos    extras      11 M
 golang-pkg-linux-amd64        noarch    1.3.3-1.el7.centos    extras     6.6 M
 golang-src                    noarch    1.3.3-1.el7.centos    extras     5.5 M
 kernel-headers                x86_64    3.10.0-123.9.3.el7    updates    1.4 M
 libmpc                        x86_64    1.0.1-3.el7           base        51 k
 mpfr                          x86_64    3.1.1-4.el7           base       203 k
Transaction Summary
================================================================================
Install  1 Package (+10 Dependent packages)
Total download size: 51 M
Installed size: 181 M
Is this ok [y/d/N]: y
Downloading packages:
(1/11): cpp-4.8.2-16.2.el7_0.x86_64.rpm                    | 5.9 MB   00:01
(2/11): gcc-4.8.2-16.2.el7_0.x86_64.rpm                    |  16 MB   00:02
(3/11): glibc-devel-2.17-55.el7_0.1.x86_64.rpm             | 1.0 MB   00:01
(4/11): glibc-headers-2.17-55.el7_0.1.x86_64.rpm           | 650 kB   00:00
(5/11): kernel-headers-3.10.0-123.9.3.el7.x86_64.rpm       | 1.4 MB   00:00
(6/11): golang-1.3.3-1.el7.centos.x86_64.rpm               | 2.6 MB   00:00
(7/11): libmpc-1.0.1-3.el7.x86_64.rpm                      |  51 kB   00:00
(8/11): golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_ |  11 MB   00:01
(9/11): mpfr-3.1.1-4.el7.x86_64.rpm                        | 203 kB   00:00
(10/11): golang-src-1.3.3-1.el7.centos.noarch.rpm          | 5.5 MB   00:01
(11/11): golang-pkg-linux-amd64-1.3.3-1.el7.centos.noarch. | 6.6 MB   00:06
--------------------------------------------------------------------------------
Total                                              5.5 MB/s |  51 MB  00:09
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mpfr-3.1.1-4.el7.x86_64                                     1/11
  Installing : libmpc-1.0.1-3.el7.x86_64                                   2/11
  Installing : cpp-4.8.2-16.2.el7_0.x86_64                                 3/11
  Installing : kernel-headers-3.10.0-123.9.3.el7.x86_64                    4/11
  Installing : glibc-headers-2.17-55.el7_0.1.x86_64                        5/11
  Installing : glibc-devel-2.17-55.el7_0.1.x86_64                          6/11
  Installing : gcc-4.8.2-16.2.el7_0.x86_64                                 7/11
  Installing : golang-src-1.3.3-1.el7.centos.noarch                        8/11
  Installing : golang-pkg-linux-amd64-1.3.3-1.el7.centos.noarch            9/11
  Installing : golang-1.3.3-1.el7.centos.x86_64                           10/11
  Installing : golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_64       11/11
  Verifying  : cpp-4.8.2-16.2.el7_0.x86_64                                 1/11
  Verifying  : golang-pkg-bin-linux-amd64-1.3.3-1.el7.centos.x86_64        2/11
  Verifying  : golang-1.3.3-1.el7.centos.x86_64                            3/11
  Verifying  : gcc-4.8.2-16.2.el7_0.x86_64                                 4/11
  Verifying  : golang-src-1.3.3-1.el7.centos.noarch                        5/11
  Verifying  : kernel-headers-3.10.0-123.9.3.el7.x86_64                    6/11
  Verifying  : glibc-devel-2.17-55.el7_0.1.x86_64                          7/11
  Verifying  : mpfr-3.1.1-4.el7.x86_64                                     8/11
  Verifying  : glibc-headers-2.17-55.el7_0.1.x86_64                        9/11
  Verifying  : libmpc-1.0.1-3.el7.x86_64                                  10/11
  Verifying  : golang-pkg-linux-amd64-1.3.3-1.el7.centos.noarch           11/11
Installed:
  golang.x86_64 0:1.3.3-1.el7.centos
Dependency Installed:
  cpp.x86_64 0:4.8.2-16.2.el7_0
  gcc.x86_64 0:4.8.2-16.2.el7_0
  glibc-devel.x86_64 0:2.17-55.el7_0.1
  glibc-headers.x86_64 0:2.17-55.el7_0.1
  golang-pkg-bin-linux-amd64.x86_64 0:1.3.3-1.el7.centos
  golang-pkg-linux-amd64.noarch 0:1.3.3-1.el7.centos
  golang-src.noarch 0:1.3.3-1.el7.centos
  kernel-headers.x86_64 0:3.10.0-123.9.3.el7
  libmpc.x86_64 0:1.0.1-3.el7
  mpfr.x86_64 0:3.1.1-4.el7
Complete!

Now the moment of truth:

[[email protected] root]$ go version
go version go1.3.3 linux/amd64

Awesome.

Environmental Variables

If you check your environmental variables, you will see that references to Go are "mysteriously" missing:

[[email protected] root]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] root]$ echo $GOPATH
[[email protected] root]$

In CentOS you have a ~/.bash_profile file that you can update to handle this. By default, it will look a little something like this:

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH

Update the file to include $GOPATH and make sure to append the bin subdirectory of your $GOPATH to your $PATH variable:

export GOPATH=$HOME/go
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$GOPATH/bin

After you source your ~/.bash_profile file, you should now have the appropriate values for these variables:

[[email protected] root]$ source ~/.bash_profile
[[email protected] root]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/home/quinn/.local/bin:/home/quinn/bin:/home/quinn/go/bin
[[email protected] root]$ echo $GOPATH
/home/quinn/go

Excellent.

Note: You can also see all of your Go environment information using go env:

[[email protected] bin]$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/quinn/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Installing Git & Mercurial

In order to "get" revel (next step) we need both git and hg (Mercurial). To install, simply run:

[[email protected] ~]$ sudo yum install git
[[email protected] ~]$ sudo yum install hg

For brevity, I am not including the output. The install is actually very speedy (rock on Digital Ocean!), but there were a lot of dependencies in both cases.

Sidenote: How to determine if you need Git, Hg, or both
For me, it was a case of trial and error. When I attempted to "get" revel with out both Git and Hg, I received an error that I did not have the other package. i.e. When I only had git, I received the error go: missing Mercurial command. Likewise when I only had Hg, I received the error go: missing Git command.

Installing EPEL

You will also need EPEL. To install, I followed these instructions.

[[email protected] ~]$ cd /tmp
[[email protected] tmp]$ sudo yum install wget
[[email protected] tmp]$ wget https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm

Again, for brevity, I have not included the install output.

Sidenote: yum install method
I also tried sudo yum install epel-release-7-2.noarch.rpm, but received the following message: No package epel-release-7-2.noarch.rpm available.

Installing Revel

To install Revel we need to use go get. Good thing we installed git and hg, eh?

[[email protected] tmp]$ go get github.com/revel/cmd/revel

(If all goes smoothly, you should have no output.)

Now for the moment of truth:

[[email protected] tmp]$ revel run github.com/revel/revel/samples/chat
~
~ revel! http://revel.github.io
~
2014/12/03 21:10:19 revel.go:326: Loaded module static
2014/12/03 21:10:19 revel.go:326: Loaded module testrunner
2014/12/03 21:10:19 run.go:57: Running chat (github.com/revel/revel/samples/chat) in dev mode
2014/12/03 21:10:19 harness.go:165: Listening on :9000

SUCCESS.

Addenda

  • go get uses the same type of version control system as the package that you are "getting".
  • As a new user to CentOS I am still not 100% clear what EPEL provides for the revel install – however without it you will be plagued with errors.

Spread the word

twitter icon facebook icon linkedin icon