How to install and configure Golang

王林
Release: 2024-07-17 14:16:07
Original
731 people have browsed it

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
Copy after login

Install Go

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

Configure Go

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

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"
Copy after login

Run this to update your terminal and apply the changes:

source ~/.profile
# Or with zsh:
source ~/.zprofile
Copy after login

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

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
Copy after login

Paste this at the end of the file:

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/
Copy after login

Done!

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

The above is the detailed content of How to install and configure Golang. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!