How to Install Golang in Ubuntu Linux 18.04 using apt package manager

Posted on

Introduction

This is an article with one specific main focus. It is showing how to install a new package with the name of golang. The installation process is in Ubuntu Linux 18.04 operating system. It uses apt package manager and it exists in the form of command. It is for managing package of tool. In other words, installing golang is possible using apt package manager.

Installation Process

Before the installation, switch to ‘root’ account. Basically, just do all the following steps for installing golang.

1. First step,  check the package with the name of golang.  It is important  whether golang exist or not in the operating system :

root@hostname:~# apt list --installed | grep golang

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

root@hostname:~# 

2. Furthermore, there is no package with the name of golang according to the output above.  So, just carry on to the next step. Obviously, it is a step for installing go. Just type the following command :

root@hostname:~# apt -y install golang
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libssl-doc pkg-php-tools shtool
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  golang-1.10 golang-1.10-doc golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src golang-doc golang-go golang-race-detector-runtime golang-src pkg-config
Suggested packages:
  bzr mercurial subversion
The following NEW packages will be installed:
  golang golang-1.10 golang-1.10-doc golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src golang-doc golang-go golang-race-detector-runtime golang-src pkg-config
0 upgraded, 11 newly installed, 0 to remove and 122 not upgraded.
Need to get 42,8 MB of archives.
After this operation, 229 MB of additional disk space will be used.
Get:1 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic-updates/main amd64 golang-1.10-src amd64 1.10.4-2ubuntu1~18.04.1 [11,1 MB]
Get:2 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic-updates/main amd64 golang-1.10-go amd64 1.10.4-2ubuntu1~18.04.1 [28,6 MB]                                                                                 
Get:3 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic-updates/main amd64 golang-1.10-doc all 1.10.4-2ubuntu1~18.04.1 [2.419 kB]                                                                                 
Get:4 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic-updates/main amd64 golang-1.10 all 1.10.4-2ubuntu1~18.04.1 [11,2 kB]                                                                                      
Get:5 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang-src amd64 2:1.10~4ubuntu1 [3.676 B]                                                                                                     
Get:6 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang-go amd64 2:1.10~4ubuntu1 [22,0 kB]                                                                                                      
Get:7 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang-doc all 2:1.10~4ubuntu1 [2.944 B]                                                                                                       
Get:8 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang amd64 2:1.10~4ubuntu1 [2.896 B]                                                                                                         
Get:9 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang-1.10-race-detector-runtime amd64 0.0+svn285455-0ubuntu1 [478 kB]                                                                        
Get:10 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 pkg-config amd64 0.29.1-0ubuntu2 [45,0 kB]                                                                                                    
Get:11 http://xxx.xxxx.xxxxx.xxx/ubuntu bionic/main amd64 golang-race-detector-runtime amd64 2:1.10~4ubuntu1 [3.456 B]                                                                                  
Fetched 42,8 MB in 37s (1.150 kB/s)                                                                                                                                                                        
Selecting previously unselected package golang-1.10-src.
(Reading database ... 326347 files and directories currently installed.)
Preparing to unpack .../00-golang-1.10-src_1.10.4-2ubuntu1~18.04.1_amd64.deb ...
Unpacking golang-1.10-src (1.10.4-2ubuntu1~18.04.1) ...
Selecting previously unselected package golang-1.10-go.
Preparing to unpack .../01-golang-1.10-go_1.10.4-2ubuntu1~18.04.1_amd64.deb ...
Unpacking golang-1.10-go (1.10.4-2ubuntu1~18.04.1) ...
Selecting previously unselected package golang-1.10-doc.
Preparing to unpack .../02-golang-1.10-doc_1.10.4-2ubuntu1~18.04.1_all.deb ...
Unpacking golang-1.10-doc (1.10.4-2ubuntu1~18.04.1) ...
Selecting previously unselected package golang-1.10.
Preparing to unpack .../03-golang-1.10_1.10.4-2ubun
tu1~18.04.1_all.deb ...
Unpacking golang-1.10 (1.10.4-2ubuntu1~18.04.1) ...
Selecting previously unselected package golang-src.
Preparing to unpack .../04-golang-src_2%3a1.10~4ubuntu1_amd64.deb ...
Unpacking golang-src (2:1.10~4ubuntu1) ...
Selecting previously unselected package golang-go.
Preparing to unpack .../05-golang-go_2%3a1.10~4ubuntu1_amd64.deb ...
Unpacking golang-go (2:1.10~4ubuntu1) ...
Selecting previously unselected package golang-doc.
Preparing to unpack .../06-golang-doc_2%3a1.10~4ubuntu1_all.deb ...
Unpacking golang-doc (2:1.10~4ubuntu1) ...
Selecting previously unselected package golang.
Preparing to unpack .../07-golang_2%3a1.10~4ubuntu1_amd64.deb ...
Unpacking golang (2:1.10~4ubuntu1) ...
Selecting previously unselected package golang-1.10-race-detector-runtime.
Preparing to unpack .../08-golang-1.10-race-detector-runtime_0.0+svn285455-0ubuntu1_amd64.deb ...
Unpacking golang-1.10-race-detector-runtime (0.0+svn285455-0ubuntu1) ...
Selecting previously unselected package pkg-config.
Preparing to unpack .../09-pkg-config_0.29.1-0ubuntu2_amd64.deb ...
Unpacking pkg-config (0.29.1-0ubuntu2) ...
Selecting previously unselected package golang-race-detector-runtime.
Preparing to unpack .../10-golang-race-detector-runtime_2%3a1.10~4ubuntu1_amd64.deb ...
Unpacking golang-race-detector-runtime (2:1.10~4ubuntu1) ...
Setting up golang-1.10-race-detector-runtime (0.0+svn285455-0ubuntu1) ...
Setting up golang-race-detector-runtime (2:1.10~4ubuntu1) ...
Setting up pkg-config (0.29.1-0ubuntu2) ...
Setting up golang-1.10-src (1.10.4-2ubuntu1~18.04.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up golang-src (2:1.10~4ubuntu1) ...
Setting up golang-1.10-go (1.10.4-2ubuntu1~18.04.1) ...
Setting up golang-1.10-doc (1.10.4-2ubuntu1~18.04.1) ...
Setting up golang-go (2:1.10~4ubuntu1) ...
Setting up golang-1.10 (1.10.4-2ubuntu1~18.04.1) ...
Setting up golang-doc (2:1.10~4ubuntu1) ...
Setting up golang (2:1.10~4ubuntu1) ...
root@hostname:~# 

Testing the golang utility

Finally, after installing go in the previous section, just try to execute it. Just do the following steps :

1. First of all, check whether the golang package exist after the previous installation. Just type the following command :

root@hostname:~# apt list --installed | grep golang

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

golang/bionic,now 2:1.10~4ubuntu1 amd64 [installed]
golang-1.10/bionic-updates,bionic-updates,now 1.10.4-2ubuntu1~18.04.1 all [installed,automatic]
golang-1.10-doc/bionic-updates,bionic-updates,now 1.10.4-2ubuntu1~18.04.1 all [installed,automatic]
golang-1.10-go/bionic-updates,now 1.10.4-2ubuntu1~18.04.1 amd64 [installed,automatic]
golang-1.10-race-detector-runtime/bionic,now 0.0+svn285455-0ubuntu1 amd64 [installed,automatic]
golang-1.10-src/bionic-updates,now 1.10.4-2ubuntu1~18.04.1 amd64 [installed,automatic]
golang-doc/bionic,bionic,now 2:1.10~4ubuntu1 all [installed,automatic]
golang-go/bionic,now 2:1.10~4ubuntu1 amd64 [installed,automatic]
golang-race-detector-runtime/bionic,now 2:1.10~4ubuntu1 amd64 [installed,automatic]
golang-src/bionic,now 2:1.10~4ubuntu1 amd64 [installed,automatic]
root@hostname:~# 

2. Next, switch to normal user.

3. After that, execute the ‘go’ command as follows :

user@hostname:/usr/bin$ go
Go is a tool for managing Go source code.

Usage:

    go command [arguments]

The commands are:

    build       compile packages and dependencies
    clean       remove object files and cached files
    doc         show documentation for package or symbol
    env         print Go environment information
    bug         start a bug report
    fix         update packages to use new APIs
    fmt         gofmt (reformat) package sources
    generate    generate Go files by processing source
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         report likely mistakes in packages

Use "go help [command]" for more information about a command.

Additional help topics:

    c           calling between Go and C
    buildmode   build modes
    cache       build and test caching
    filetype    file types
    gopath      GOPATH environment variable
    environment environment variables
    importpath  import path syntax
    packages    package lists
    testflag    testing flags
    testfunc    testing functions

Use "go help [topic]" for more information about that topic.

user@hostname:/usr/bin$

Actually, executing the ‘go’ command according  in the above output is a success. So,  the installation of ‘go’ is actually finished.

Leave a Reply