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 deploy go program to linux and run it?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the go program deployed to run on the linux how to achieve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that everyone after reading this go program deployed to run on the linux how to achieve the article will have a harvest, let's take a look.

Go language version: go1.9.2

Development environment: win10

Deployment environment: ubuntu 14.04.6

1. Operations on win10

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

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

Go build main.go

Report the mistake of "cannot find package" golang.org/x/sys/unix

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 under gopath, and create it manually if golang.org\ x does not exist

Rerun the go build main.go command and generate the main file in the current directory

2. Ubuntu on linux

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

2. Start the program

1), execute the. / main command

If you report "Permission denied" wrong

Solution: give executable permissions to main files

Chmod 777 main

Run. / main again and the program starts normally

2) start the program in the background

The startup method of. / main stops when the console exits. We can use the nohup. / main & command to make the program run in the background

Nohup. / main &

3) check whether the program is running properly

Ps aux | grep main

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

This is the end of the article on "how to deploy go programs on linux". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to deploy go programs to linux". If you want to learn more, you are welcome to follow the industry information channel.

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