Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop Go with Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to use Linux to develop Go, the content is very detailed, interested friends can refer to, hope to be helpful to you.

I still remember when I was in college, installing a Linux system was still a complicated thing.

First download the image, then carve it into the CD, and then install it on the CD.

The biggest headache is that the quality of the CD-ROM drive of my laptop is not very good, so I don't know if the installation step is wrong, or my CD-ROM drive doesn't work well in the first place.

Of course, I can also install it in a virtual machine, but I just want to install it directly in the hardware.

Now that there are major cloud server manufacturers, it is easy for you to own one of your Linux servers.

Beginners get a Linux server, often do not know how to use, looking at the command line scalp numb, here I will clean it up for you, so that you can use the Linux system more smoothly.

The system I use is CentOS8, and the corresponding other Linux operating systems should be similar.

1. Remote login tool

Generally speaking, when we do server development, we have to use the remote terminal to log in to the Linux server, and then do the corresponding operation.

XShell and SeucreCrt are both very useful tools, so you can try them. I use Xshell myself, because it has a free version, so you don't have to bother to crack it.

Generally, when purchasing a CVM, the manufacturer will let you set your user name and password. Here, I use root users to log in directly.

two。 Set up the software source

The software source that comes with Linux may be slow, so we can replace it with a domestic source.

Run the following command

Mv / etc/yum.repos.d/CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repo.backup yum makecache sed-I-e'/ mirrors.cloud.aliyuncs.com/d'-e'/ mirrors.aliyuncs.com/d' / etc/yum.repos.d/CentOS-Base.repo yum-y update

3. Install rzsz tools

This is a set of upload and download tools, you can easily upload your local files to the cloud server, as well as download the cloud server files to the local.

Yum install lrzsz

Download is sz command, upload is rz command

4. Install vim

The vim version that comes with CentOS8 is already quite high, so you don't have to reinstall it.

If the version is relatively low, you can install the latest version of vim. Because a higher version of vim is required for subsequent installation of the vim-go plug-in.

Because I use vim all the time, I use vim to do everything I need to edit later.

I also hope that readers will learn to use vim, because it will make your job much easier (server only).

The installation steps are as follows:

Yum install gcc ncurses-devel wget https://github.com/vim/vim/archive/master.zip unzip master.zip cd vim-master/src/. / configure make make install

5. Configure vimrc

To make the vim editor set up for better use, we can configure the .vimrc file.

This is my own configuration, which readers can download and put in the / root directory.

Link: https://pan.baidu.com/s/1yJBuDEDggjUqEt76r9difg extraction code: imy2.

This file follows the user, and when you switch to another user, you need to put it in the appropriate user directory.

6. Configure environment variables

The environment variable can be configured under the two files / root/.bash_rc / root/.bash_profile, just choose one.

These two files also follow the user, and when you switch to another user, switch to the corresponding user's environment variable.

My configuration is as follows, the original code of the file does not need to be moved, just add these later.

PS1=' [\ t\ u @\ H:\ W]\ 'PATH=PATH:~/bin:~/go/bin:~/gopkg/bin.UTF-8 GOROOT=~/go GOPATH=~/gopkg GO111MODULE=on GOPROXY= https://goproxy.cn,direct GOCACHE=~/gocache GOBIN=~/bin export PATH export LD_LIBRARY_PATH export LANG export GOROOT export GOPATH export GOPROXY export GO111MODULE export GOCACHE export GOBIN

PS1 sets the format of the bash command prompt, which can be set to different styles according to your preferences, and the details can be checked on your own.

PATH sets the directory where executable commands are stored.

LANG sets the language encoding format.

The following six settings are all Go-related variables, which are set here, so you don't have to set them later when you install Go.

After setting up, export through export.

And save it.

It will not take effect until you run the following command:

Source .bashrc

6. Install Go

Go to https://golang.google.cn/ to download the latest Go installation package, currently go1.15.2.linux-amd64.tar.

Download and upload to the server through the rz tool.

Run:

Tar xvf go1.15.2.linux-amd64.tar-C.

Because we have configured the environment variables before, all we have to do is decompress it.

Run the following command, and if you output the version number of go, the installation is successful.

Go version

7.vim installs the Go plug-in

To make it easier to use vim for Go programming, you can install the vim-go plug-in, which integrates many Go tools.

Run the command:

Yum install git git clone https://github.com/fatih/vim-go.git ~ / .vim/pack/plugins/start/vim-go vim: GoInstallBinaries waiting for installation

After the installation, we can write the code happily.

On how to use Linux to develop Go to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report