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

Установка 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, либо вы хотите вручную установить самую последнюю версию компилятора, то следуйте этому руководству далее.

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

Читайте также:  Autorun program in 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.

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

Источник

Installing Golang on Kali Linux

If you are anything like me, you are more likely to Google how to install a golang than do an apt search. If that brought you here, then this is what you are after:

# First, install the package sudo apt install -y golang # Then add the following to your .bashrc export GOROOT=/usr/lib/go export GOPATH=$HOME/go export PATH=$GOPATH/bin:$GOROOT/bin:$PATH # Reload your .bashrc source .bashrc 

At this point you should be ready to Go. You can test by writing and compiling the Hello World program from Golang’s webpage.

package main import "fmt" func main()  fmt.Printf("hello, world\n") > 

Save this as hello.go . You can then build this with go build hello.go . This should yield an executable file named hello .

With this setup, Go modules will be downloaded to your home directory and compiled there. As you start to get more Go programs installed, they will all be put in /go , which may be what you want, but my preference is to install each program into a separate directory. As a result, I use something similar to the following python script to change the prefix for each Go module so that it installs into a separate /opt directory and soft links to /usr/local/bin . You’ll need to change the list of modules to install to your preferences, but it should work as is:

#!/usr/bin/env python3 import os import sys def install_golang_module(module): ''' Install the specified Golang module ''' modulename = module.split("/")[-1].lower() if not os.path.exists("/opt/" + modulename): print("Installing go module " + modulename) cmdseries = ["sudo -E GO111MODULE=on go get -v " + module, "sudo ln -s /opt/" + modulename + "/bin/" + \ modulename + " /usr/local/bin/" + modulename] os.environ["GOPATH"] = "/opt/" + modulename for cmdstring in cmdseries: os.system(cmdstring) if __name__ == '__main__': ''' These go tools will be installed globally. ''' golang_modules_to_install = ['github.com/tomnomnom/assetfinder', 'github.com/lc/gau', 'github.com/theblackturtle/wildcheck', 'github.com/tomnomnom/httprobe', 'github.com/hakluke/hakrawler', 'github.com/tomnomnom/qsreplace', 'github.com/hahwul/dalfox'] for module in golang_modules_to_install: install_golang_module(module) 

The full update script I use normally does a bunch of additional things, in an effort to keep all my environments at parity. You can take a look at github.com/rafaelh/update-kali.

You will also see GO111MODULE in a lot of Go installation commands. I recommend the following post to understand what this is about.

Now that you have Go working, take a look at the following repositories:

Источник

Installing Golang on Kali Linux

If you are anything like me, you are more likely to Google how to install a golang than do an apt search. If that brought you here, then this is what you are after:

# First, install the package sudo apt install -y golang # Then add the following to your .bashrc export GOROOT=/usr/lib/go export GOPATH=$HOME/go export PATH=$GOPATH/bin:$GOROOT/bin:$PATH # Reload your .bashrc source .bashrc 

At this point you should be ready to Go. You can test by writing and compiling the Hello World program from Golang’s webpage.

package main import "fmt" func main()  fmt.Printf("hello, world\n") > 

Save this as hello.go . You can then build this with go build hello.go . This should yield an executable file named hello .

With this setup, Go modules will be downloaded to your home directory and compiled there. As you start to get more Go programs installed, they will all be put in /go , which may be what you want, but my preference is to install each program into a separate directory. As a result, I use something similar to the following python script to change the prefix for each Go module so that it installs into a separate /opt directory and soft links to /usr/local/bin . You’ll need to change the list of modules to install to your preferences, but it should work as is:

#!/usr/bin/env python3 import os import sys def install_golang_module(module): ''' Install the specified Golang module ''' modulename = module.split("/")[-1].lower() if not os.path.exists("/opt/" + modulename): print("Installing go module " + modulename) cmdseries = ["sudo -E GO111MODULE=on go get -v " + module, "sudo ln -s /opt/" + modulename + "/bin/" + \ modulename + " /usr/local/bin/" + modulename] os.environ["GOPATH"] = "/opt/" + modulename for cmdstring in cmdseries: os.system(cmdstring) if __name__ == '__main__': ''' These go tools will be installed globally. ''' golang_modules_to_install = ['github.com/tomnomnom/assetfinder', 'github.com/lc/gau', 'github.com/theblackturtle/wildcheck', 'github.com/tomnomnom/httprobe', 'github.com/hakluke/hakrawler', 'github.com/tomnomnom/qsreplace', 'github.com/hahwul/dalfox'] for module in golang_modules_to_install: install_golang_module(module) 

The full update script I use normally does a bunch of additional things, in an effort to keep all my environments at parity. You can take a look at github.com/rafaelh/update-kali.

You will also see GO111MODULE in a lot of Go installation commands. I recommend the following post to understand what this is about.

Now that you have Go working, take a look at the following repositories:

Источник

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