search
HomeBackend DevelopmentGolangGo Ubuntu: Old School Style

Go   Ubuntu: Old School Style

If you're the type of person who likes cute interfaces and feature-packed tools, this article might not be for you. Here, let's do things the old-fashioned way, like our ancestors did. In the end, you will leave with Go installed and running, without the need for IDEs or polished interfaces (in case the frontend world ends for good).

What you will need:

  • Distributions based on Debian/Ubuntu, as the commands here are specific to this scenario;
  • Visual Studio Code installed (step-by-step link);
  • Sanity (optional, depending on the level of your GUI needs).

Installation

Open the terminal and paste the following command:

sudo apt install golang-go
  • sudo: is necessary to ensure that the command will be executed with administrator permissions (the famous "root");

  • apt: is the Ubuntu package management tool, used to install, update and remove software;

  • install: indicates that we are asking the system to install a new package;

  • golang-go: is the package you are installing, that is, Go (also known as Golang).

This command will install the version of Go present in the official Ubuntu repositories. The disadvantage is that this version is often not the most recent, as the repositories may not always be updated with the latest versions of all tools.


What if I want the most current version of Go?

To ensure you have the latest version of Go available, use the following commands:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
  • sudo add-apt-repository ppa:longsleep/golang-backports: is the command that will add a backports repository to your system. Backport repositories are like “alternative paths” to obtain newer versions of packages that are not in the official repository;

  • sudo apt update: will update the list of available packages and ensure that the system is aware of this new source of packages;

  • sudo apt install golang-go: ensures that you download the most current version of Go available in this backports repository.


Checking the installed version

After installation, check if Go was installed correctly by running the following command:

go version

This should return something like:

go version go1.23.4 linux/amd64

Now you're ready to take over the world with Go... or at least finish following the tutorial, if you don't mind.

It went wrong, what now?

Now turn around, right? The world will not dominate itself alone.


Programming in Go using VSCode

Now that Go is in the system, it's time to code using the VSCode terminal (I promise it doesn't hurt).

Open VSCode through the terminal with the command:

sudo apt install golang-go

Create a new project:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go

If the following message in vbnet is as follows, then it means it worked.

go version

Now, run the ls command to list the files and create the directory structure:

go version go1.23.4 linux/amd64
  • mkdir: the command used to create a directory (a folder);

  • -p: option that allows you to create subdirectories, if they do not exist, without generating an error. For example, if you want to create a folder inside another, -p will create all the folders in the path at once;

  • project-name: is the name you choose for the directory that will be created, that is, we are creating the folder where we will store all the files of your Go project;

  • cd: means "change directory", changing directory. It is used to navigate between directories (folders) on your file system;

  • project-name: is the directory we just entered. So, after running this command, the terminal will be inside the project-name folder, where you can start working and adding files;

  • touch: command used to create an empty file. In this case, it creates the main.go file within the project-name directory (if the file already exists, the command updates the modification date and time);

  • main.go: Go file where we will write the code for our project;

  • code: command to open VSCode, if you have it installed and configured in your terminal;

  • main.go: file you just created, which will be opened directly in VSCode. This is useful to launch the file and start programming in Go directly from within the editor.

Now, finally inside main.go, paste the following code for a simple "Hello":

code .

Run via terminal:

go mod init nome-projeto

Ready! Now you will definitely dominate the world.


Want to be more old school? More coming!

Now, if you want to be more "thick", how about creating the file directly in the terminal without using a text editor?

Open the terminal in Ubuntu and create a file called hello.go with the Go code directly in it:

go: creating new go.mod: module projeto
go: to add module requirements and sums:
        go mod tidy
  • echo -e allows you to print multiple lines of text in the terminal (and -e interprets line breaks and other special characters);

  • The text between the quotes is the Go code we are inserting into the file;

  • > hello.go redirects the output of the echo command to the file hello.go.

Now, let's definitely raise the level.


Running...

sudo apt install golang-go

This command will compile and execute the Go file at the same time, resulting in:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go

Modifying the code directly in the terminal

If you want to make small changes to the code directly in the terminal, you can use echo again. For example, if you want to change the message to "Hello, World!", run the command:

go version

Then run again:

go version go1.23.4 linux/amd64

Tip: using echo with redirection is a quick and effective way to create small files directly through the terminal. However, for larger projects, you will need a text editor like nano or vim in the terminal.


Conclusion

No more, except that now you are a true legend, and you will make this world a bluer place. GO!

The above is the detailed content of Go Ubuntu: Old School Style. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Interfaces and Polymorphism in Go: Achieving Code ReusabilityInterfaces and Polymorphism in Go: Achieving Code ReusabilityApr 29, 2025 am 12:31 AM

InterfacesandpolymorphisminGoenhancecodereusabilityandmaintainability.1)Defineinterfacesattherightabstractionlevel.2)Useinterfacesfordependencyinjection.3)Profilecodetomanageperformanceimpacts.

What is the role of the 'init' function in Go?What is the role of the 'init' function in Go?Apr 29, 2025 am 12:28 AM

TheinitfunctioninGorunsautomaticallybeforethemainfunctiontoinitializepackagesandsetuptheenvironment.It'susefulforsettingupglobalvariables,resources,andperformingone-timesetuptasksacrossanypackage.Here'showitworks:1)Itcanbeusedinanypackage,notjusttheo

Interface Composition in Go: Building Complex AbstractionsInterface Composition in Go: Building Complex AbstractionsApr 29, 2025 am 12:24 AM

Interface combinations build complex abstractions in Go programming by breaking down functions into small, focused interfaces. 1) Define Reader, Writer and Closer interfaces. 2) Create complex types such as File and NetworkStream by combining these interfaces. 3) Use ProcessData function to show how to handle these combined interfaces. This approach enhances code flexibility, testability, and reusability, but care should be taken to avoid excessive fragmentation and combinatorial complexity.

Potential Pitfalls and Considerations When Using init Functions in GoPotential Pitfalls and Considerations When Using init Functions in GoApr 29, 2025 am 12:02 AM

InitfunctionsinGoareautomaticallycalledbeforethemainfunctionandareusefulforsetupbutcomewithchallenges.1)Executionorder:Multipleinitfunctionsrunindefinitionorder,whichcancauseissuesiftheydependoneachother.2)Testing:Initfunctionsmayinterferewithtests,b

How do you iterate through a map in Go?How do you iterate through a map in Go?Apr 28, 2025 pm 05:15 PM

Article discusses iterating through maps in Go, focusing on safe practices, modifying entries, and performance considerations for large maps.Main issue: Ensuring safe and efficient map iteration in Go, especially in concurrent environments and with l

How do you create a map in Go?How do you create a map in Go?Apr 28, 2025 pm 05:14 PM

The article discusses creating and manipulating maps in Go, including initialization methods and adding/updating elements.

What is the difference between an array and a slice in Go?What is the difference between an array and a slice in Go?Apr 28, 2025 pm 05:13 PM

The article discusses differences between arrays and slices in Go, focusing on size, memory allocation, function passing, and usage scenarios. Arrays are fixed-size, stack-allocated, while slices are dynamic, often heap-allocated, and more flexible.

How do you create a slice in Go?How do you create a slice in Go?Apr 28, 2025 pm 05:12 PM

The article discusses creating and initializing slices in Go, including using literals, the make function, and slicing existing arrays or slices. It also covers slice syntax and determining slice length and capacity.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version