DEV Community

Cover image for Golang 101: ติดตั้ง Go บน Mac ด้วย Homebrew
ทรงเดฟ
ทรงเดฟ

Posted on

Golang 101: ติดตั้ง Go บน Mac ด้วย Homebrew

** หมายเหตุ ** บทความนี้ต้องการ Homebrew ดังนั้นควรติดตั้ง Homebrew ก่อน โดยสามารถทำตามลิ้งค์นี้ได้เลย Dev 101: ติดตั้ง Homebrew บน Mac

  1. เปิด Terminal เพื่อเตรียมพร้อมสำหรับการรันคำสั่งในขั้นตอนต่อไป

Terminal

  1. สั่ง brew update เพื่อให้เช็คข้อมูลต่าง ๆ เช่น version ให้เป็นปัจจุบัน และติดตั้ง golang
brew update && brew install golang
Enter fullscreen mode Exit fullscreen mode
  1. ทดลองใช้ เพื่อเช็คว่าติดตั้งสมบูรณ์หรือไม่ เช่น การเช็คเวอร์ชัน
go version
Enter fullscreen mode Exit fullscreen mode

ถ้าหากได้ผลลัพธ์ดังนี้ แปลว่าติดตั้งสมบูรณ์

Test go install is complete with check version


แถม: ทดสอบการรันไฟล์ Go

  1. สร้างไฟล์นามสกุล .go

Test run .go file

  1. รันไฟล์ Go

2.1. รันผ่านไฟล์ go โดยตรง ไม่ต้อง build ไฟล์ executable ออกมา

go run test.go
Enter fullscreen mode Exit fullscreen mode

2.2. รันผ่านไฟล์ executable

go build test.go
Enter fullscreen mode Exit fullscreen mode

และ

./test.go
Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay