# Install & Run

{% hint style="warning" %}
Always remove previous versions before installing newer ones.
{% endhint %}

## Install

### Manually

Officially, Go docs tells to manually download the latest version and install it.

```bash
wget https://go.dev/dl/go1.xx.x.linux-amd64.tar.gz
sudo rm -rf /opt/go && sudo tar -C /opt -xzf go1.*.linux-amd64.tar.gz
```

Add this env to `.bashrc`.

```bash
export PATH=$PATH:/usr/local/go/bin
```

### Version manager

There is a [version manager](https://github.com/stefanmaric/g) kind of like python `pyenv`.

It automatically adds the Path variables to `.bashrc` and installs the latest Go version.

```bash
wget -qO- https://git.io/g-install | sh -s
```

Other commands:

```bash
# Download and set version to latest
g install latest

# Download and set to <version>
g install <version>

# List installed versions
g list

# List all versions
g list-all

# Remove all versions, except the current used one
g prune
```

## Compile & Run

### Run uncompiled

Run an uncompiled `file.go` file with:

```
go run file.go
```

### Compile

{% hint style="warning" %}
To build and generate an executable the project needs a [Broken link](https://kdongs.gitbook.io/kdocs/golang/broken-reference "mention").
{% endhint %}

```
go build
```

### Run compiled

In Windows the compiled will be a `.exe` file, whether in Linux or Mac it will be a executable file.
