نصب اخرین ورژن گولنگ بر روی سرور های لینوکس ایران

9/13/2024 Go(golang)
65

مشکل اینه توی اینترنت نصب گولنگ برای سرور لینوکس با ای پی به جز ایران  ساده به نظر میاد 

بااستفاده از دستور snap در لینوکس شما اخرین ورژن golang رو نخواهید داشت و بااستفاده از apt هم به همین منوال اخرین ورژن golang رو نخواهید داشت

برای داشتن اخرین ورژن گولنگ استفاده از wget  و ادرس اخرین ورژن انلاین گولنگ هست https://go.dev/doc/install

 و برای نصب از دستور زیر استفاده کنیم 

wget -c https://golang.org/dl/go<last-ver>.linux-amd64.tar.gz

 

اگر ایران نباشید به راحتی نصب میشود مشکل جایی ایجاد میشود با ای پی ایران که از ایران بخواهید گولنگ را نصب کنید

برای نصب در سرور لینوکس باید دی ان اس DNS تنظیم کنید در لینوکس سرور خودتون این دستور را اجرا کنید 

nano /etc/resolv.conf

این صفحه را خواهید دید

# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search .

 

برای تغییرلازم است این کار را انجام دهد

# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

# nameserver 127.0.0.53

nameserver 10.202.10.202
nameserver 10.202.10.102
options edns0 trust-ad
search .

- برای نصب caddy به یاد داشته باشید دی ان اس ها را حذف کنید

اشتباه قبل از این فایل این بود که 

nameserver 127.0.053 را به صورت کامنت در نیوروده بودم 

و در انتها با درستور 

wget -c https://golang.org/dl/go<last-ver>.linux-amd64.tar.gz

گولنگ دانلود میشود (فقط به یاد داشته باشید به حای <last-ver>) از صفحه گولنگ اخرین ورژن گولنگ را دانلود کنید

و سپس با دستر زیر فایل زیپ شده گولنگ را به/usr/local/go  کپی میکنیم و قایل زیپ را حذف میکنیم 

 rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz

برای من بعد از دستور بالا خطایی اینچنین داشتم 

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

فایل دانلود شده را خذف کردم و دوباره دانلود کردم و بعد دستور کپی و اکسترکت را اجرا کردم و انجام شد

حال لازم است تا به لینوکس اعلام کنیم در دستورات پیشفرض خود از دستورات گولنگ هم استفاده کند و به کاربر این اجازه را بدهد که از دستورات go استفاده کند 

دستور زیر را در terminal وارد میکنیم 

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

و برای استفاده لازم است سیستم را ریستارت کنیم و یا دستور زیر را اجرا کنیم 

 source $HOME/.profile

حال میتوانیم با دستور 

 go version

ببینیم ایا GOLANG نصب شده