Files
learngo/01-get-started/ubuntu-installation.md

119 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2018-11-17 16:41:36 +03:00
# Linux Installation Cheatsheet
If you want to use snap, you can easily install Go like so:
sudo snap install go --classic
Otherwise, please follow the steps below:
2018-11-17 16:41:36 +03:00
## 1. Update the local packages
```bash
sudo apt-get update
```
## 2. Install git
```bash
sudo apt-get install git
```
## 3. Install Go
2019-02-16 08:49:38 +03:00
There are two ways:
1- From Web: Select Linux and the download will begin.
2018-11-17 16:41:36 +03:00
```bash
firefox https://golang.org/dl
```
2019-02-16 08:49:38 +03:00
2- By using snap: If you use this option, skip to the 5th step.
```bash
sudo snap install go --classic
```
2018-11-17 16:41:36 +03:00
## 4. Copy Go into the proper directory
1. Find out the name of the downloaded file
2019-02-16 08:49:38 +03:00
2018-11-17 16:41:36 +03:00
2. Use that filename to uncompress it
```bash
gofile="DELETE_THIS_AND_TYPE_THE_NAME_OF_THE_DOWNLOADED_FILE_HERE (without its extension)"
2019-02-16 08:49:38 +03:00
tar -C /usr/local -xzf ~/Downloads/$gofile
2018-11-17 16:41:36 +03:00
```
2019-02-16 08:49:38 +03:00
## 5. Add Go executables directory to your PATH
1. Add `go/bin` directory to `$PATH` to be able to run the fundamental Go commands.
2018-11-17 16:41:36 +03:00
```bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
```
2019-02-16 08:49:38 +03:00
2. Add "$HOME/go/bin" directory to $PATH
2018-11-17 16:41:36 +03:00
```bash
echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile
```
## Install Go Tools:
* These are very handy tools to ease the development (like goimports)
2018-11-18 05:03:43 +08:00
* `go get` cannot be used without installing a code versioning program like Git which we already have got it above.
2018-11-17 16:41:36 +03:00
* This will create `~/go` directory and will download go tools into there.
* This directory is also a place where you should put your code into.
(If you're not going to use Go Modules)
```bash
go get -v -u golang.org/x/tools/...
```
2019-05-11 16:23:55 +03:00
## Install VSCode (Optional)
2018-11-17 16:41:36 +03:00
2019-02-16 08:49:38 +03:00
Note: You may use another coding editor if you like. However, the course uses Visual Studio Code (VSCode).
2018-11-17 16:41:36 +03:00
1. Open "Ubuntu Software" application
2019-02-16 08:49:38 +03:00
2018-11-17 16:41:36 +03:00
2. Search for VSCode then click "Install"
2019-02-16 08:49:38 +03:00
2018-11-17 16:41:36 +03:00
## OPTIONAL STEP:
2019-05-11 16:23:55 +03:00
1. Create a hello.go file in a new directory but anywhere outside of `$GOPATH`
2018-11-17 16:41:36 +03:00
```bash
2019-05-11 16:23:55 +03:00
cat <<EOF > hello.go
2018-11-17 16:41:36 +03:00
package main
2018-11-18 05:03:43 +08:00
2018-11-17 16:41:36 +03:00
import "fmt"
2018-11-18 05:03:43 +08:00
2018-11-17 16:41:36 +03:00
func main() {
fmt.Println("hello gopher!")
}
EOF
```
2019-05-11 16:23:55 +03:00
2. Run the program
2018-11-17 16:41:36 +03:00
```bash
go run hello.go
It should print: hello gopher!
```
<div style="page-break-after: always;"></div>
> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)
2018-11-18 05:03:43 +08:00
>
2018-11-17 16:41:36 +03:00
> Copyright © 2018 Inanc Gumus
2018-11-18 05:03:43 +08:00
>
2018-11-17 16:41:36 +03:00
> Learn Go Programming Course
2018-11-18 05:03:43 +08:00
>
> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)