
Go also known as Golang is an open-source programming language designed for simplicity, reliability, and efficiency. Go is a fast, statically typed compiled language suitable for developing scalable web servers, cloud-native applications, and command-line tools.
This guide explains how to install Go on Debian 12. You'll also manage multiple Go versions to meet different project requirements.
Before you begin:
Go is available in the default APT package repositories on Debian 12. Follow the steps below to install Go on your server.
Update the server's package information index.
Install Go.
View the installed Go version.
Output:
Follow the steps below to create a sample application to verify that Go runs correctly on your server.
Create a new go-sample project directory.
Switch to the go-sample directory.
Initialize a new example.com/hello Go module in the directory,
Create a new main.go application file using a text editor like nano.
Add the following contents to the main.go file.
Save and close the file.
The above Go application displays a Greeting from Vultr message when you run it.
Run the main.go application file.
Output:
Maintaining multiple Go versions on your system allows you to meet different project requirements. You can use the Go version manager (GVM) or manually install specific Go versions in your project environment. Follow the steps below to install and manage multiple GO versions using both methods.
Follow the steps below to install multiple Go versions from source.
Visit the Go releases webpage and download a specific Go version's archive file. For example, download the Go version 1.23.0.
Run the following command to download another Go version such as 1.21.0.
Create a new /usr/local/go1.23.0 directory to store the 1.23.0 Go version files.
Create another /usr/local/go1.21.0 directory to store the 1.21.0 Go version files.
Extract the 1.23.0 Go archive files to the /usr/local/go1.23.0 directory.
Extract the 1.21.0 Go archive files to the /usr/local/go1.21.0 directory.
Create a new PATH environment variable and set the 1.23.0 Go version to activate it as the default on the server.
Verify the active Go version.
Output:
Create a new go123 alias for the 1.23.0 Go version to access it using a single command.
Create another go121 alias for the 1.21.0 Go version to access it using a single command.
Reload your shell configuration to apply the changes.
Run the alias command associated with the installed Go version. For example, run the main.go application you created earlier using the 1.23.0 Go version.
Output:
Run the main.go application file using the go121 alias command.
Output:
Repeat the above process for each Go version to install and run multiple Go versions on the server.
Go Version Manager (GVM) allows you to manage and switch between Go versions. You can use GVM to install and use specific Go versions without manually setting up a PATH variable or downloading any binary packages. Follow the steps below to install GVM and manage multiple Go versions.
Update the server's package information index.
Install all required GVM dependency packages.
Download and install GVM using the latest installation script.
Reload your shell configuration to apply the changes.
Use GVM to install a specific Go version. For example, Go version 1.20.8.
Output:
Set the 1.20.8 Go version as the default.
Output:
View the active Go version.
Output:
Install another Go version. For example, Go version 1.21.5.
List all installed Go versions.
Output:
Run the following command to switch to a specific Go version such as go1.21.5 in your shell environment.
You have installed Go on Debian 12 and managed multiple versions. You can use Go with popular libraries, frameworks, and databases to create modern applications. For more information, visit the Go documentation.
0 Comments
Be the first to comment and share your perspective with the community.