Установка golang linux mint

How To Install Go 1.20 on LinuxMint 21/20/19

Go is an open-source programming language developed by a team at Google. It provides easy-to-build simple, reliable, and efficient software. This language is designed for writing servers, that’s why it is used widely these days. Go has released the latest version 1.20.

This tutorial will help you to install Go 1.20 on your LinuxMint 21/20/19 systems.

To install Golang on Debian system visit below link:

Step 1: Install Golang on Linux Mint

Login to your Linux Mint system using ssh and upgrade to apply the latest security updates.

sudo apt-get update sudo apt-get upgrade 

Then download the Go language binary archive file using the following link. To find and download latest version available or 32 bit version go to official download page.

wget https://go.dev/dl/go1.20.linux-amd64.tar.gz 

Now extract the downloaded archive and install it to the desired location on the system. For this tutorial, I am installing it under /usr/local directory. You can also put this under the home directory (for shared hosting) or other location.

tar -xvf go1.19.linux-amd64.tar.gz mv go /usr/local 

Step 2: Setup Go Environment

Now you need to setup Go language environment variables for your project. Commonly you need to set 3 environment variables as GOROOT, GOPATH and PATH.

GOROOT is the location where Go package is installed on your system.

GOPATH is the location of your work directory. For example my project directory is ~/Projects/Proj1 .

export GOPATH=$HOME/Apps/app1 

Now set the PATH variable to access go binary system wide.

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH 

All above environment will be set for your9 current session only. To make it permanent add above commands in ~/.profile file.

Читайте также:  Линукс консоль логин и пароль

Step 3: Verify Installation

At this step, you have successfully installed and configured go language on your system. First, use the following command to check the Go version.

go version  go version go1.20 linux/amd64

Now also verify all configured environment variables using following command.

go env  GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build661994963=/tmp/go-build" CXX="g++" CGO_ENABLED="1"

Источник

Установка Go (компилятора и инструментов) в Linux

Установка Go из стандартных системных репозиториев в Debian, Kali Linux, Linux Mint, Ubuntu

Для установки выполните команду:

Для Debian также рекомендуется добавить экспорт следующих переменных окружения в файле ~/.bashrc (или ~/.zshrc если у вас ZSH):

export GOPATH=/home/$USER/go export PATH=$:$GOROOT/bin:/home/$USER/go/bin

Эти изменения вступят в силу после перезагрузки. Вместо перезапуска компьютера выполните:

source ~/.bashrc # или source ~/.zshrc

Если вы не уверены, какая у вас оболочка, то выполните команду:

  • /bin/bash — значит у вас Bash
  • /usr/bin/zsh — значит у вас ZSH

Установка Go из стандартных системных репозиториев в Arch Linux, BlackArch и их производные

В Arch Linux и производные Go устанавливается следующим образом:

Для Arch Linux также рекомендуется добавить экспорт следующих переменных окружения в файле ~/.bashrc (или ~/.zshrc):

export GOPATH=/home/$USER/go export PATH=$:$GOROOT/bin:/home/$USER/go/bin

Эти изменения вступят в силу после перезагрузки. Вместо перезапуска компьютера выполните:

source ~/.bashrc # или source ~/.zshrc

Ручная установка самой последней версии компилятора Go

Ранее рекомендовалась именно ручная установка, поскольку она предусматривает добавление переменных окружения. Переменные окружения используются, например, в командах по установке, которые дают разработчики программ:

go get github.com/Ullaakut/cameradar cd $GOPATH/src/github.com/Ullaakut/cameradar/cmd/cameradar go install

Без переменных окружения эта последовательность команд завершиться ошибкой.

Но эти переменные окружения можно добавить и при установке Go из репозитория, как это показано выше. Поэтому если вы это сделали (добавили экспорт переменных окружения), то каких либо преимуществ у ручной установки нет. Разве что, только если вам нужна самая последняя версия языка Go.

Если в источниках приложений для вашего дистрибутива отсутствует Go, либо вы хотите вручную установить самую последнюю версию компилятора, то следуйте этому руководству далее.

Читайте также:  Debian gnu linux wheezy

Следующая инструкция успешно протестирована в Kali Linux, Arch Linux, BlackArch, Linux Mint, Ubuntu. Также она должна работать в практически любом дистрибутиве Linux.

Если вы не уверены, какая у вас оболочка, то выполните команду:

  • /bin/bash — значит у вас Bash
  • /usr/bin/zsh — значит у вас ZSH

Если у вас Bash оболочка (большинство систем), то следуйте инструкциям из этого раздела:

Откройте файл .bashrc в директории пользователя любым текстовым редактором:

И для создания новых переменных окружения добавьте следующие строки в этот файл:

export GOPATH=/home/$USER/go export GOROOT=/usr/local/src/go export PATH=$:$GOROOT/bin:/home/$USER/go/bin

Когда всё готово, сохраните изменения и закройте файл.

Эти изменения вступят в силу после перезагрузки. Вместо перезапуска компьютера выполните:

Если у вас ZSH оболочка (по умолчанию, например, в Kali Linux), то следуйте инструкциям из этого раздела:

Откройте файл ~/.zshrc в директории пользователя любым текстовым редактором:

И для создания новых переменных окружения добавьте следующие строки в этот файл:

export GOPATH=/home/$USER/go export GOROOT=/usr/local/src/go export PATH=$:$GOROOT/bin:/home/$USER/go/bin

Когда всё готово, сохраните изменения и закройте файл.

Эти изменения вступят в силу после перезагрузки. Вместо перезапуска компьютера выполните:

Дальше одинаково для всех оболочек и систем.

Следующая команда автоматически определит и скачает последнюю версию файлов языка программирования Go:

wget https://golang.org/`curl -s https://golang.org/dl/ | grep -E -o 'dl/go[0-9.]linux-amd64.tar.gz' | head -n 1`

Извлеките скаченный архив:

tar zxf go*.linux-amd64.tar.gz

Переместить в директорию на $GOROOT, которую мы указали в ~/.bashrc.

Теперь наберите в терминале:

Источник

Install Go on Linux Mint 20

Install Go on Linux Mint 20

Go is a relatively newer statically typed and compiled programming language that was developed in 2009. A Go program is a combination of functions and methods. This programming language provides a great level of liberty and flexibility to coders and hence it is used quite extensively. Let us take a look at the procedure of installing this language on a Linux machine.

The procedure of Installing Go on Linux Mint 20:

If you want to install Go language on your Linux system, then you should perform the steps described over here on your system.

Step # 1: Perform a System Update:

Before installing Go language on your system, it is good to have an updated system that can be achieved by executing the command shown below:

$ sudo apt-get update

This command will complete its execution with the following output:

Читайте также:  Connect linux and mac

Step # 2: Install Go on your System:

Now, you can install Go language on your Linux system with this command:

$ sudo apt-get install golang

During the installation, you need to provide a confirmation with the “y” character and press the Enter key as shown below:

Finally, Go language will be installed on your system and you will be able to verify it as well.

Step # 3: Check the Installed Version of Go on your System:

To confirm which version of Go language has been installed on your Linux system, you can execute the following command:

$ go version

You can see the version of Go language installed on our system in the image below:

Step # 4: Create a Program in Go Language on your System:

To further test your installation of Go language on your system, you can create a program in this language and try to execute it. First, you need to create a file with the “.go” extension by executing this command:

$ sudo nano FileName.go

After creating a Go file, we have created a simple program that prints a sample message on the terminal as shown below. You can save this file by pressing Ctrl+ X.

Step # 5: Run the Go Program you have just created on your System:

Now, it is time to run our Go program with the following command:

$ go run FileName.go

The output of our first Go language program is shown in the image below:

Additional Tip:

You can also remove the Go language from your Linux system very easily with the following command:

$ sudo apt-get purge --autoremove golang

Soon after running this command, the Go language will be completely removed from your Linux system.

Conclusion:

This was a very basic introductory article on the installation of the Go language on a Linux Mint 20 system. Moreover, we also shared with you a very quick method of creating a sample Go program. Finally, we concluded this guide on the removal procedure of Go language from a Linux Mint 20 system.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Источник

Оцените статью
Adblock
detector