Home  >  Article  >  System Tutorial  >  Make Linux server a good helper for Go developers

Make Linux server a good helper for Go developers

WBOY
WBOYforward
2024-02-13 19:51:111168browse

Installing a Linux system is still a relatively complicated matter for many people, let alone using a Linux system to develop Go. But now, with the convenience provided by major cloud server manufacturers, you can easily own a Linux server and just log in using a remote terminal. For those newbies who are not familiar with Linux systems and Go development, here are some simple settings and steps to help you use Linux systems to develop Go programs more smoothly.

Make Linux server a good helper for Go developers
  • I still remember when I was in college, installing a Linux system was still a relatively complicated matter.
  • You need to download the image first, then burn it to a CD, and then install it with the CD.
  • The biggest headache is that the quality of the optical drive in my laptop is not very good, so I don't know if there is a problem because the installation steps are wrong or because my optical drive is not running well in the first place.
  • Of course, I can also install it in a virtual machine, but I am paranoid and want to install it directly in the hardware.
  • Nowadays, with major cloud server manufacturers, you can easily own a Linux server.
  • When novices get a Linux server, they often don't know how to use it, and their scalp goes numb looking at the command line. Here I will sort it out 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 when we do server development, we must use a remote terminal to log in to the Linux server, and then perform corresponding operations.

XShell and SeucreCrt are both very useful tools. You can try them. I use Xshell myself, because it has a free version, so I don’t have to worry about cracking it.

Generally when purchasing a cloud server, the manufacturer will ask you to set a username and password. Here I directly use the root user to log in.

2. Set up the software source

The software source that comes with Linux may be slow, 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 tool

This is a set of upload and download tools that can easily upload your local files to the cloud server and download the files from the cloud server to the local.

yum install lrzsz

Download is the sz command, upload is the rz command

4. Install vim

The vim version that comes with CentOS8 is already quite high, so there is no need to reinstall it.

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

Because I have always used vim, I will use vim to complete the places that need to be edited later.

I also hope that readers can learn to use vim, because it will make your work a lot easier (server direction 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

In order to make the vim editor more useful, we can configure the .vimrc file.
This is my own configuration. Readers can download it and put it in the /root directory.
Link: https://pan.baidu.com/s/1yJBuDEDggjUqEt76r9difg Extraction code: imy2.

This file follows the user. When you switch to another user, it needs to be placed in the corresponding user directory.

6. Configure environment variables

Environment variables can be configured under the two files /root/.bash_rc /root/.bash_profile, just choose one.

These two files also follow the user. When you switch to another user, you switch to the environment variables of the corresponding user.

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

PS1='[\t \u@\H:\w]\'
PATH=PATH:~/bin:~/go/bin:~/gopkg/bin
LANG=zh_CN.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. You can set it to different styles according to your own preferences. You can check the specific details by yourself.

PATH sets the directory where executable commands are stored.

LANG sets the language encoding format.

The following 6 settings are all Go-related variables. Once set here, you will not need to set them when you install Go later.

After setting up, export through export.

Then save.

It will take effect after running the following command:

source .bashrc

6. Install Go

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

After downloading, upload it to the server through the rz tool.

run:

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

Because we have configured environment variables before, we only need to decompress it here.

Run the following command. If the go version number is output, the installation is successful.

 go version

7.vim install Go plug-in

In order to use vim for Go programming more conveniently, 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
等待安装

After installation, we can happily write code.

8. Summary

Using a Linux system to develop Go programs may still be a challenge for some people, but these basic settings and steps we provide can help you get started easily. With just some time and effort, you can make your Linux server a great helper for developing Go programs. Whether you're a newbie or an experienced developer, you'll benefit from this introductory tutorial.

The above is the detailed content of Make Linux server a good helper for Go developers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete