Packaging release

Linux packages are distributed in one of two ways: as source code or as a binary (compiled) package. When shipped as source code, a makefile, or similar, would be included to instruct the compiler on how to create the executable. With Go, this is different due to the standard structure and build tools, so we don't need to include a make file. As developers, we simply invoke go install for the current project or go get for one that is not yet downloaded. Anyone familiar with Go will know this process and so there is no required build information in this case.

However, we are packaging for distribution to regular users, not developers. For this to work , we could use distribution-specific packaging (which we will look at later in this chapter) or build a package that could work for any Linux system. To do the latter, we can prepare a structured package that can simply be expanded onto a user's system. The standard installation location for non-system packages is /usr/local, so we start at that location for our files (we mirror this structure in the current directory). The expected tree of files should look like the following (hicolor is the name of the fallback theme for looking up icons):

File path Description
usr/local/share/applications/myapp.desktop Desktop Entry metadata 
usr/local/share/icons/hicolor/512x512/apps/myapp.png Application icon (for a 512 x 512 px bitmap image)
usr/local/share/icons/hicolor/scalable/apps/myapp.svg Application icon (for a vector image)
usr/local/bin/myapp Executable file (from go build)

With all of these files in the right folder we can build an application package using the tar utility. The full command to create a new file with this content is tar -cf myapp.tar.gz usr, as shown in the following screenshot:

Packaging the contents of our usr/local directory structure

The resulting package can be shared for installation, and the recipient should use sudo tar -xf myapp.tar.gz from the root of their filesystem. In this example, we pass the additional -C / to avoid having to change directory, as indicated in the following screenshot:

After installing the packaged application we can run it from $PATH

This package format will work for all Linux distributions, but packaging for package managers is additional work. We will look at distribution tools later in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.159.82