Home > Backend Development > Golang > How to deploy go program to run on linux

How to deploy go program to run on linux

藏色散人
Release: 2021-05-18 16:13:10
forward
4121 people have browsed it

The following tutorial column of golang will introduce to you how to deploy the go program to run on linux. I hope it will be helpful to friends in need!

How to deploy go program to run on linux

go language version: go1.9.2

Development environment: win10

Deployment environment: ubuntu 14.04.6

1. Operation on win10

1. Execute the set CGO_ENABLED=0, set GOOS=linux, and set GOARCH=amd64 commands in the src directory in sequence

##2. Enter the main project directory and execute the go build program entry file. Here is main.go

go build main.go

reported "cannot find package "golang.org/x/sys/unix" error


Solution:

1), download the third-party package code

git clone https://github.com/golang/sys.git

2), Transfer the entire downloaded sys folder to the src folder golang.org\x folder under gopath. If golang.org\x does not exist, create it manually

Rerun the go build main.go command , the main file will be generated in the current directory

##2. Linux side ubuntu

1. Copy the files required by the program such as configuration files and generated executables Copy the executable file to ubuntu. Here is the conf folder and main file

2. Start the program

1), execute the ./main command

If a "Permission denied" error is reported

Solution: Give the main file executable permissions

chmod 777 main

Run ./main again, the program starts normally

2), start the program in the background

./ The main startup method will stop the program when the console exits. We can use the nohup ./main & command to let the program run in the background.

nohup ./main &

3) Check whether the program is running normally

ps aux|grep main

##You can see that the program is running normally on 32297pid

At this point, the Go application deployment and running on the Linux server has been completed.

The above is the detailed content of How to deploy go program to run on linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template