Home Backend Development Golang How to install golang mac

How to install golang mac

Mar 29, 2023 am 09:24 AM
golang mac

Golang is a simple, fast, safe and efficient concurrency programming language. It is available on various operating systems, including macOS. In this article, we will discuss how to install Golang on macOS.

1. Download Golang
Before starting the installation, you need to download the latest version of Golang from https://golang.org/dl/. Golang installation files are usually less than 100MB in size, so the download speed should be fast.

2. Install Golang

  1. Open the terminal
    On macOS, you can open the terminal by finding it in the application. You can also use the shortcut "Command Space" to open Spotlight and then enter "Terminal" to search for it.
  2. Configure installation path
    Enter the following command in the terminal to create a new directory to store Golang binaries.

mkdir $HOME/go

Next, open the .bash_profile file with the following command:

open -e $HOME/.bash_profile

In the opened file, add the following content at the end:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

  1. Install Golang
    Next, open the Golang installation file downloaded in the first step. This will unpack the Golang binaries into the "/usr/local/go" directory. However, in order for macOS to be able to find Golang's binaries, it needs to be added to the PATH environment variable. Complete the task through the following command:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile

Next, restart the terminal .

  1. Check the installation
    After the installation is complete, you can check whether Golang is installed correctly by entering the following command in the terminal:

go version

If the command returns the currently running Golang version number, the installation is successful.

3. Run the first program
Next, we will create a simple "Hello, World!" program and run it. Enter the following command in the terminal:

mkdir $HOME/go/src/hello
cd $HOME/go/src/hello
echo 'package main

import "fmt "

func main() {

fmt.Println("Hello, World!")
Copy after login

}' > hello.go

Compile and run the program with the following command:

go run hello. go

Terminal output is as follows:

Hello, World!

This is the successful running of your first Golang program. Congratulations!

Summary
Golang is a very popular programming language, especially suitable for writing relatively small applications. Installing it on macOS is very simple and can be done easily even if you are a newbie. Just follow the steps provided in this article, and you can easily install Golang on the macOS platform and start writing your own programs.

The above is the detailed content of How to install golang mac. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to safely read and write files using Golang? How to safely read and write files using Golang? Jun 06, 2024 pm 05:14 PM

How to safely read and write files using Golang?

How to configure connection pool for Golang database connection? How to configure connection pool for Golang database connection? Jun 06, 2024 am 11:21 AM

How to configure connection pool for Golang database connection?

Apple iPhone 16 is no longer pre-installed with Apple Intelligence Apple iPhone 16 is no longer pre-installed with Apple Intelligence Jul 30, 2024 pm 01:18 PM

Apple iPhone 16 is no longer pre-installed with Apple Intelligence

Similarities and Differences between Golang and C++ Similarities and Differences between Golang and C++ Jun 05, 2024 pm 06:12 PM

Similarities and Differences between Golang and C++

ChatGPT is now available for macOS with the release of a dedicated app ChatGPT is now available for macOS with the release of a dedicated app Jun 27, 2024 am 10:05 AM

ChatGPT is now available for macOS with the release of a dedicated app

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

How steep is the learning curve of golang framework architecture?

MacBook Pro, iMac to get the M4 upgrade later this year followed by MacBook Air in spring of 2025, claims reliable tipster MacBook Pro, iMac to get the M4 upgrade later this year followed by MacBook Air in spring of 2025, claims reliable tipster Jun 25, 2024 am 06:35 AM

MacBook Pro, iMac to get the M4 upgrade later this year followed by MacBook Air in spring of 2025, claims reliable tipster

Comparison of advantages and disadvantages of golang framework Comparison of advantages and disadvantages of golang framework Jun 05, 2024 pm 09:32 PM

Comparison of advantages and disadvantages of golang framework

See all articles