"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to install and configure Golang

How to install and configure Golang

Published on 2024-08-02
Browse:693

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

Install Go

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

Configure Go

sudo nano ~/.profile
# Or with zsh:
sudo nano ~/.zprofile

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"

Run this to update your terminal and apply the changes:

source ~/.profile
# Or with zsh:
source ~/.zprofile

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}"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub

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

Paste this at the end of the file:

[url "ssh://[email protected]/"]
    insteadOf = https://github.com/

Done!

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

Release Statement This article is reproduced at: https://dev.to/henriqueleite42/how-to-install-and-configure-golang-4619?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3