Customized installation Golang on Linux
COMPILERS FOLDER
Example: mkdir {compilers,compilers/c,compilers/go,compilers/rust}
mkdir {compilers,compilers/go}
cd compilers/go
VERSION
mkdir go1.17.6.linux-amd64 && cd go1.17.6.linux-amd64
DOWNLOAD
wget https://dl.google.com/go/go1.17.6.linux-amd64.tar.gz
- Write the command
dir
then hitEnter
to check if the foldergo1.17.6.linux-amd64.tar.gz
is completely downloaded.
EXTRACT & REMOVE
tar -xvf go1.17.6.linux-amd64.tar.gz
rm go1.17.6.linux-amd64.tar.gz
WORK SPACE
IF there is no such file or directory "~/dev/golang/workspace", then create this directory
cd ~
mkdir {dev,dev/golang,dev/golang/workspace}
Or go to the Golang development directory like so
cd ~/dev/golang/workspace
Workspace required to enable Golang versions
mkdir go1.17.6 && cd go1.17.6
mkdir {bin,pkg,src,src/github.com,src/github.com/your-github-name}
An example of what a workspace looks like
workspace
├── go1.15.7
├── go1.16
├── go1.16.2
├── go1.16.3
├── go1.16.4
└── go1.17.6
├── bin
├── pkg
└── src
└── github.com
└── your-github-name
PATH
Open the terminal path file by writing
gedit $HOME/.bashrc
OR
gedit ~/.bashrc
Copy
, Paste
& Save
the following code at the end of the .bashrc
file, then close it.
## Changes made to the .bashrc file by myself
## GOROOT
export GOROOT=$HOME/compilers/go/go1.17.6.linux-amd64/go
export PATH=$PATH:$GOROOT/bin
## GOPATH
export GOPATH=$HOME/dev/golang/workspace/go1.17.6
export PATH=$PATH:$GOPATH/bin
## GOBIN
export GOBIN=${GOPATH}/bin
Note:
only one version must be active
CHECK
Close the terminal and open it again
go version
go version go1.17.6 linux/amd64
go env
GO111MODULE="auto"
GOPATH="/home/<your-usr-name>/dev/golang/workspace/go1.17.6"
GOBIN="/home/<your-usr-name>/dev/golang/workspace/go1.17.6/bin"
GOROOT="/home/<your-usr-name>/compilers/go/go1.17.6.linux-amd64/go"
GOCACHE="/home/<your-usr-name>/.cache/go-build"
GOENV="/home/<your-usr-name>/.config/go/env"
GOMODCACHE="/home/<your-usr-name>/dev/golang/workspace/go1.17.6/pkg/mod"
GOTOOLDIR="/home/montasir/compilers/go/go1.17.6.linux-amd64/go/pkg/tool/linux_amd64"
TEST PROJECT
go get github.com/gorilla/mux
cd dev/golang/workspace/go1.17.6/src/github.com/your-github-name
git clone https://github.com/dr-montasir/go-rest-api.git
cd go-rest-api/go-mock-rest-api
go build
go run main.go
OR
./go-mock-rest-api
Open your browser and test the project
http://localhost:1400/api/courses
[
{
"id": "1",
"category": "Web Development",
"title": "Build Web Apps with Go Language",
"instructor": { "firstName": "Rob", "lastName": "Pike" },
"cousreDuration": "4 months"
},
{
"id": "2",
"category": "Mobile App Development",
"title": "Build Mobile Apps with Flutter Dart",
"instructor": { "firstName": "Lars", "lastName": "Bak" },
"cousreDuration": "5 months"
}
]
How to test the project outside of GOPATH?
cd ~/Desktop
git clone https://github.com/dr-montasir/go-rest-api.git
cd go-rest-api/go-mock-rest-api
go build
OR
go build -o alternative-project-name main.go