code.gitea.io/gitea@v1.22.3/docs/content/installation/from-source.en-us.md (about)

     1  ---
     2  date: "2016-12-01T16:00:00+02:00"
     3  title: "Installation from source"
     4  slug: "install-from-source"
     5  sidebar_position: 30
     6  toc: false
     7  draft: false
     8  aliases:
     9    - /en-us/install-from-source
    10  menu:
    11    sidebar:
    12      parent: "installation"
    13      name: "From source"
    14      sidebar_position: 30
    15      identifier: "install-from-source"
    16  ---
    17  
    18  # Installation from source
    19  
    20  You should [install go](https://go.dev/doc/install) and set up your go
    21  environment correctly. In particular, it is recommended to set the `$GOPATH`
    22  environment variable and to add the go bin directory or directories
    23  `${GOPATH//://bin:}/bin` to the `$PATH`. See the Go wiki entry for
    24  [GOPATH](https://github.com/golang/go/wiki/GOPATH).
    25  
    26  Next, [install Node.js with npm](https://nodejs.org/en/download/) which is
    27  required to build the JavaScript and CSS files. The minimum supported Node.js
    28  version is @minNodeVersion@ and the latest LTS version is recommended.
    29  
    30  **Note**: Go version @minGoVersion@ or higher is required. However, it is recommended to
    31  obtain the same version as our continuous integration, see the advice given in
    32  [Hacking on Gitea](development/hacking-on-gitea.md)
    33  
    34  ## Download
    35  
    36  First, we must retrieve the source code. Since, the advent of go modules, the
    37  simplest way of doing this is to use Git directly as we no longer have to have
    38  Gitea built from within the GOPATH.
    39  
    40  ```bash
    41  git clone https://github.com/go-gitea/gitea
    42  ```
    43  
    44  (Previous versions of this document recommended using `go get`. This is
    45  no longer necessary.)
    46  
    47  Decide which version of Gitea to build and install. Currently, there are
    48  multiple options to choose from. The `main` branch represents the current
    49  development version. To build with main, skip to the [build section](#build).
    50  
    51  To work with tagged releases, the following commands can be used:
    52  
    53  ```bash
    54  git branch -a
    55  git checkout v@version@
    56  ```
    57  
    58  To validate a Pull Request, first enable the new branch (`xyz` is the PR id;
    59  for example `2663` for [#2663](https://github.com/go-gitea/gitea/pull/2663)):
    60  
    61  ```bash
    62  git fetch origin pull/xyz/head:pr-xyz
    63  ```
    64  
    65  To build Gitea from source at a specific tagged release (like v@version@), list the
    66  available tags and check out the specific tag.
    67  
    68  List available tags with the following.
    69  
    70  ```bash
    71  git tag -l
    72  git checkout v@version@  # or git checkout pr-xyz
    73  ```
    74  
    75  ## Build
    76  
    77  To build from source, the following programs must be present on the system:
    78  
    79  - `go` @minGoVersion@ or higher, see [here](https://go.dev/dl/)
    80  - `node` @minNodeVersion@ or higher with `npm`, see [here](https://nodejs.org/en/download/)
    81  - `make`, see [here](development/hacking-on-gitea.md#installing-make)
    82  
    83  Various [make tasks](https://github.com/go-gitea/gitea/blob/main/Makefile)
    84  are provided to keep the build process as simple as possible.
    85  
    86  Depending on requirements, the following build tags can be included.
    87  
    88  - `bindata`: Build a single monolithic binary, with all assets included. Required for production build.
    89  - `sqlite sqlite_unlock_notify`: Enable support for a
    90    [SQLite3](https://sqlite.org/) database. Suggested only for tiny
    91    installations.
    92  - `pam`: Enable support for PAM (Linux Pluggable Authentication Modules). Can
    93    be used to authenticate local users or extend authentication to methods
    94    available to PAM.
    95  - `gogit`: (EXPERIMENTAL) Use go-git variants of Git commands.
    96  
    97  Bundling all assets (JS/CSS/templates, etc) into the binary. Using the `bindata` build tag is required for
    98  production deployments. You could exclude `bindata` when you are developing/testing Gitea or able to separate the assets correctly.
    99  
   100  To include all assets, use the `bindata` tag:
   101  
   102  ```bash
   103  TAGS="bindata" make build
   104  ```
   105  
   106  In the default release build of our continuous integration system, the build
   107  tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest
   108  recommended way to build from source is therefore:
   109  
   110  ```bash
   111  TAGS="bindata sqlite sqlite_unlock_notify" make build
   112  ```
   113  
   114  The `build` target is split into two sub-targets:
   115  
   116  - `make backend` which requires [Go @minGoVersion@](https://go.dev/dl/) or greater.
   117  - `make frontend` which requires [Node.js @minNodeVersion@](https://nodejs.org/en/download/) or greater.
   118  
   119  If pre-built frontend files are present it is possible to only build the backend:
   120  
   121  ```bash
   122  TAGS="bindata" make backend
   123  ```
   124  
   125  ## Test
   126  
   127  After following the steps above, a `gitea` binary will be available in the working directory.
   128  It can be tested from this directory or moved to a directory with test data. When Gitea is
   129  launched manually from command line, it can be killed by pressing `Ctrl + C`.
   130  
   131  ```bash
   132  ./gitea web
   133  ```
   134  
   135  ## Changing default paths
   136  
   137  Gitea will search for a number of things from the _`CustomPath`_. By default this is
   138  the `custom/` directory in the current working directory when running Gitea. It will also
   139  look for its configuration file _`CustomConf`_ in `$(CustomPath)/conf/app.ini`, and will use the
   140  current working directory as the relative base path _`AppWorkPath`_ for a number configurable
   141  values. Finally the static files will be served from _`StaticRootPath`_ which defaults to the _`AppWorkPath`_.
   142  
   143  These values, although useful when developing, may conflict with downstream users preferences.
   144  
   145  One option is to use a script file to shadow the `gitea` binary and create an appropriate
   146  environment before running Gitea. However, when building you can change these defaults
   147  using the `LDFLAGS` environment variable for `make`. The appropriate settings are as follows
   148  
   149  - To set the _`CustomPath`_ use `LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=custom-path\""`
   150  - For _`CustomConf`_ you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
   151  - For _`AppWorkPath`_ you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
   152  - For _`StaticRootPath`_ you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"`
   153  - To change the default PID file location use `-X \"code.gitea.io/gitea/cmd.PIDFile=/run/gitea.pid\"`
   154  
   155  Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
   156  with the appropriate `TAGS` as above.
   157  
   158  Running `gitea help` will allow you to review what the computed settings will be for your `gitea`.
   159  
   160  ## Cross Build
   161  
   162  The `go` compiler toolchain supports cross-compiling to different architecture targets that are supported by the toolchain. See [`GOOS` and `GOARCH` environment variable](https://go.dev/doc/install/source#environment) for the list of supported targets. Cross compilation is helpful if you want to build Gitea for less-powerful systems (such as Raspberry Pi).
   163  
   164  To cross build Gitea with build tags (`TAGS`), you also need a C cross compiler which targets the same architecture as selected by the `GOOS` and `GOARCH` variables. For example, to cross build for Linux ARM64 (`GOOS=linux` and `GOARCH=arm64`), you need the `aarch64-unknown-linux-gnu-gcc` cross compiler. This is required because Gitea build tags uses `cgo`'s foreign-function interface (FFI).
   165  
   166  Cross-build Gitea for Linux ARM64, without any tags:
   167  
   168  ```
   169  GOOS=linux GOARCH=arm64 make build
   170  ```
   171  
   172  Cross-build Gitea for Linux ARM64, with recommended build tags:
   173  
   174  ```
   175  CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
   176  ```
   177  
   178  Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target.
   179  
   180  You will sometimes need to build a static compiled image. To do this you will need to add:
   181  
   182  ```
   183  LDFLAGS="-linkmode external -extldflags '-static' $LDFLAGS" TAGS="netgo osusergo $TAGS" make build
   184  ```
   185  
   186  This can be combined with `CC`, `GOOS`, and `GOARCH` as above.
   187  
   188  ### Adding bash/zsh autocompletion (from 1.19)
   189  
   190  A script to enable bash-completion can be found at [`contrib/autocompletion/bash_autocomplete`](https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/bash_autocomplete). This should be altered as appropriate and can be `source` in your `.bashrc`
   191  or copied as `/usr/share/bash-completion/completions/gitea`.
   192  
   193  Similarly, a script for zsh-completion can be found at [`contrib/autocompletion/zsh_autocomplete`](https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/zsh_autocomplete). This can be copied to `/usr/share/zsh/_gitea` or sourced within your
   194  `.zshrc`.
   195  
   196  YMMV and these scripts may need further improvement.
   197  
   198  ## Compile or cross-compile using Linux with Zig
   199  
   200  Follow [Getting Started of Zig](https://ziglang.org/learn/getting-started/#installing-zig) to install zig.
   201  
   202  - Compile (Linux ➝ Linux)
   203  
   204  ```sh
   205  CC="zig cc -target x86_64-linux-gnu" \
   206  CGO_ENABLED=1 \
   207  CGO_CFLAGS="-O2 -g -pthread" \
   208  CGO_LDFLAGS="-linkmode=external -v"
   209  GOOS=linux \
   210  GOARCH=amd64 \
   211  TAGS="bindata sqlite sqlite_unlock_notify" \
   212  make build
   213  ```
   214  
   215  - Cross-compile (Linux ➝ Windows)
   216  
   217  ```sh
   218  CC="zig cc -target x86_64-windows-gnu" \
   219  CGO_ENABLED=1 \
   220  CGO_CFLAGS="-O2 -g -pthread" \
   221  GOOS=windows \
   222  GOARCH=amd64 \
   223  TAGS="bindata sqlite sqlite_unlock_notify" \
   224  make build
   225  ```
   226  
   227  ## Compile or cross-compile with Zig using Windows
   228  
   229  Compile with `GIT BASH`.
   230  
   231  - Compile (Windows ➝ Windows)
   232  
   233  ```sh
   234  CC="zig cc -target x86_64-windows-gnu" \
   235  CGO_ENABLED=1 \
   236  CGO_CFLAGS="-O2 -g -pthread" \
   237  GOOS=windows \
   238  GOARCH=amd64 \
   239  TAGS="bindata sqlite sqlite_unlock_notify" \
   240  make build
   241  ```
   242  
   243  - Cross-compile (Windows ➝ Linux)
   244  
   245  ```sh
   246  CC="zig cc -target x86_64-linux-gnu" \
   247  CGO_ENABLED=1 \
   248  CGO_CFLAGS="-O2 -g -pthread" \
   249  CGO_LDFLAGS="-linkmode=external -v"
   250  GOOS=linux \
   251  GOARCH=amd64 \
   252  TAGS="bindata sqlite sqlite_unlock_notify" \
   253  make build
   254  ```
   255  
   256  ## Source Maps
   257  
   258  By default, gitea generates reduced source maps for frontend files to conserve space. This can be controlled with the `ENABLE_SOURCEMAP` environment variable:
   259  
   260  - `ENABLE_SOURCEMAP=true` generates all source maps, the default for development builds
   261  - `ENABLE_SOURCEMAP=reduced` generates limited source maps, the default for production builds
   262  - `ENABLE_SOURCEMAP=false` generates no source maps