I successfully installed this on my Mac, just having trouble on Linux. I'm following along their doc https://golang.org/doc/install. I'm running a 64bit machine so I downloaded the 64bit archive. Once downloaded I run
sudo tar -C /usr/local/ -xzf ~/Downloads/go1.4.2.linux-amd64.tar.gz
I created a go
directory in my home folder. I have the structure
/home
--/chrism
----/go
------/src
------/pkg
------/bin
And I add the following to /etc/profile
. After saving I run source /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
In src/
I added a directory git.mycompany.com
and in their another directory called test
. In test/
I made test.go
and pasted the block of code from the tutorial above in
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
When I run go run test.go
, it outputs the following
chrism@ubuntu:~/go/src/git.mycompany.com/test$ go run test.go
# fmt
Usage: pack op file.a [name....]
Where op is one of cprtx optionally followed by v for verbose output.
For compatibility with old Go build environments the op string grc is
accepted as a synonym for c.
For more information, run
godoc cmd/pack
# runtime
Usage: pack op file.a [name....]
Where op is one of cprtx optionally followed by v for verbose output.
For compatibility with old Go build environments the op string grc is
accepted as a synonym for c.
For more information, run
godoc cmd/pack
If I add more packages to my import statement, it'll output the documentation for all those packages as well.
EDIT 0:
I also tried to install with apt-get
. I uninstalled and removed my previous changes and then installed. This resulted in the following when running:
chrism@ubuntu:~/go/src/git.mycompany.com/test$ go run test.go
go build fmt: exec: "/usr/local/go/pkg/tool/linux_amd64/pack": stat /usr/local/go/pkg/tool/linux_amd64/pack: no such file or directory
go build runtime: exec: "/usr/local/go/pkg/tool/linux_amd64/pack": stat /usr/local/go/pkg/tool/linux_amd64/pack: no such file or directory
EDIT 1:
This is the output of running go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="amd64"
GOCHAR="6"
GOOS="linux"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
These are the steps I followed for installing Go in my Ubuntu system :
Short Version : 1. Run following commands for installation:
sudo apt-get remove -y gccgo-go && wget http://golang.org/dl/go1.8.linux-amd64.tar.gz && sudo apt-get -y install gcc && sudo tar -C /usr/local -xzf go1.8.2.linux-amd64.tar.gz && echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
Note: Changes the version number to install a specific version of Go. For example, to install 1.9 instead of 1.8 change the file name to go1.9.linux-amd64.tar.gz. The latest Go distributions can always be found at the official Go downloads page
Long Version:
Download the binary release from here. Use go x.x.x.linux-amd64.tar.gz for ubuntu. For version 1.4.2 you can type following in terminal.
wget http://golang.org/dl/go1.8.linux-amd64.tar.gz
Install gcc for cgo
sudo apt-get install gcc
Extract the tarball in /usr/local. It should create a go directory.
tar -C /usr/local -xzf go1.8.linux-amd64.tar.gz
(Typically these commands must be run as root or through sudo.)
Add /usr/local/go/bin to the PATH environment variable.
gksu gedit ~/.bashrc
Add following line in the end of file
export PATH=$PATH:/usr/local/go/bin
Setup Workspace
a. Create a workspace directory name go in your preferred location (unless you are using the default go installation location). I am using /home/vembu/work/projects/go
mkdir -p /home/vembu/work/projects/go
b. Export GOPATH
gedit ~/.bashrc
c. Add following line in the second last line
export GOPATH=/home/vembu/work/projects/go
d. For convenience, add the workspace's bin subdirectory to your PATH:
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
e. Finally .bashrc’s last two line should look like this
export GOPATH=/home/vembu/work/projects/go
export PATH=/usr/local/go/bin:$GOPATH/bin:$PATH
f. Restart terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With