Fresh Ubuntu 16.04 why is setting gopath so hard?

Thanks for your help. I’m OK at the command line. Why is Go installation so much harder than other languages for some reason?

Help me fix my go setup so it “just works” on Ubuntu Linux and much appreciated.

broch@broch-desktop
OS: Ubuntu 16.04 xenial
Kernel: x86_64 Linux 4.10.0-38-generic
Uptime: 2h 47m
Packages: 2311
Shell: bash 4.3.48
Resolution: 1920x1080
DE: Unity 7.4.0
WM: Compiz
WM Theme: Ambiance
Ambiance [GTK2]
, Ambiance [GTK3]
Icon Theme: ubuntu-mono-dark
Font: Ubuntu 11
CPU: AMD FX-8350 Eight-Core @ 4GHz
GPU: GeForce GTX 750 Ti
RAM: 6350MiB / 24008MiB

Example:

broch@broch-desktop:~/golang$ ls
dnssearch-master dnssearch-master.zip go1.9.2.linux-amd64.tar.gz
broch@broch-desktop:~/golang$ go build dnssearch-master
can’t load package: package dnssearch-master: cannot find package “dnssearch-master” in any of:
/snap/go/1016/src/dnssearch-master (from $GOROOT)
/home/broch/go/src/dnssearch-master (from $GOPATH)

and here is my ~/.profile file

~/.profile: executed by the command interpreter for login shells.

This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login

exists.

see /usr/share/doc/bash/examples/startup-files for examples.

the files are located in the bash-doc package.

the default umask is set in /etc/profile; for setting the umask

for ssh logins, install and configure the libpam-umask package.

#umask 022

if running bash

if [ -n “$BASH_VERSION” ]; then
# include .bashrc if it exists
if [ -f “$HOME/.bashrc” ]; then
. "$HOME/.bashrc"
fi
fi

set PATH so it includes user’s private bin directories

PATH="$HOME/bin:$HOME/.local/bin:$PATH"

export GOPATH=$HOME/broch/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

You try to install a package dnssearch-master ?

But you didn’t install Go yet. You just downloaded the binaries.

You need to run this command before setting up the path (maybe you’ve done it before but I don’t see it). :
tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz

What do you get if you run a go version ?

Why is Go installation so much harder than other languages for some reason?

Try Gopei (Go Programming Environment Installer) project to easy and safe install Go ecosystem on Linux/Unix machines. See here how to use.

1 Like

So have you made sure that there is neither of them?

Also have you logged out and in again. You have usually to do that when changing your ~/.profile that the system catches the changes.

Also when you want to go build a package X, it needs to be available in your GOPATH. In the terminal session you show, to us, the source is not in your GOPATH, neither in the one specified in the .profile ($HOME/broch/work), nor in the one thats currently used ($HOME/go).

Thanks! I will check it out and report back. I thought there might be a means to automate setting up the dev environment.

Good point. In answer, no, alas I did not reboot/re-login although I thought about it as a possible solution. I’ve got a lot of tabs open in a browser (yes session saver but still) and leave my machine on 24-7 for boinc application so I go days between reboot, but that may have solved the issue before creating a thread. Nevertheless the insight from the responses so far has been very helpful and I’ve already learned a few things. Will report results.

I used these basic steps to get up and running with the latest version of go on Debian 9. The environment is similar enough to Ubuntu, so these steps may help.

Note that I already had plenty of packages installed to help me build other development projects. You may need to install certain packages to help with the source build. That is usually very easy, since Debian/Ubuntu provides a very rich assortment of developer packages.

Note that this method of installation puts the go directories under your personal account, which is nice for learning. If you want to restructure go for “correct” deployment on your distribution, you will need to consult the packaging documentation for your distribution.

I typed many of these steps in from memory, so I cannot guarantee they are all 100% correct. I do know for sure that installation (from sources) is relatively simple and works, once you know what to do.


# INSTALL FROM SOURCES (NEED A LINX BINARY DIST TO BOOT THE GO BUILD PROCESS
# GO REQUIRES A WORKING VERSION OF GO TO BUILD FROM SOURCES

# DOWNLOAD BINARY FOR MY ARCHITECTURE
https://golang.org/doc/install?download=go1.9.2.linux-amd64.tar.gz

# DOWNLOAD LATEST SOURCES
https://golang.org/doc/install/source?download=go1.9.2.src.tar.gz

# EXTRACT BINARY DIST INTO SOME DIRECTORY AND SET ENVIRONMENT VARIABLE TO POINT TO THIS BINARY DIST
cd ~/path/to/goboot
tar xvf go1.9.2.linux-amd64.tar.gz
export GOROOT_BOOTSTRAP=/path/to/goboot/go

# EXTRACT SOURCES INTO SOME OTHER DIRECTORY AND BUILD THE SOURCES
cd ~/path/to/goinstall
tar xvf go1.9.2.src.tar.gz
cd go/src
./all.bash

# SET YOUR WORKING SHELL TO FIND THE GOPATH AND THE GO BINARY
cd ~/
vim .bashrc
	a (or whatever)
	export GOPATH=~/path/to/goprojects
	export PATH=~/path/to/goinstall/bin:$PATH
	:w
^D
bash

# YOU NEED TO FOLLOW THE GO CONVENTIONS FOR STRUCTURING YOUR PROJECTS
# YOU WILL CREATE YOUR GO PROJECTS UNDER ~/path/to/goprojects

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.