DEV Community

Henrique Leite
Henrique Leite

Posted on • Originally published at henriqueleite42.hashnode.dev

4

How to install and configure Golang

In this article, you will see how to install Golang and configure it to use the private GitHub repositories of your company.

Right to the point

BE SURE TO REPLACE {VERSION} WITH THE DESIRED VERSION THAT YOU WANT!!!

Download Go

curl -OL https://golang.org/dl/go{VERSION}.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Install Go

sudo tar -C /usr/local -xvf go{VERSION}.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Configure Go

sudo nano ~/.profile
# Or with zsh:
sudo nano ~/.zprofile
Enter fullscreen mode Exit fullscreen mode

Paste this at the end of the file, replacing {YOUR COMPANY ALIAS} with your company alias:

# Golang
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export GOPRIVATE=github.com/{YOUR COMPANY ALIAS}/*
export PATH=$PATH:$GOROOT:$GOPATH:$GOBIN
export PATH="$PATH:$(go env GOPATH)/bin"
Enter fullscreen mode Exit fullscreen mode

Run this to update your terminal and apply the changes:

source ~/.profile
# Or with zsh:
source ~/.zprofile
Enter fullscreen mode Exit fullscreen mode

Configure SSH key on GitHub

Run this, and remember to replace {YOUR EMAIL}\ with your email:

  • Run this and only press enter until the command stop

  • The ssh key MUST NOT have a password

ssh-keygen -t ed25519 -C "{YOUR EMAIL}"
Enter fullscreen mode Exit fullscreen mode
eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode
ssh-add ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode
cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Copy the content displayed on your terminal, including your email. COPY EVERYTHING that the previous command returned.

Go to GitHub and follow this tutorial to add the SSH key.

Configure Git

sudo nano ~/.gitconfig
Enter fullscreen mode Exit fullscreen mode

Paste this at the end of the file:

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/
Enter fullscreen mode Exit fullscreen mode

Done!

Now you can work with Golang and private repositories on GitHub with no problems!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay