2017-11-27 03:14:32 +05:30
---
date: "2016-12-01T16:00:00+02:00"
title: "Installation from source"
slug: "install-from-source"
weight: 10
toc: true
draft: false
menu:
sidebar:
parent: "installation"
name: "From source"
weight: 30
identifier: "install-from-source"
---
# Installation from source
2019-02-12 21:52:01 +05:30
You should [install go ](https://golang.org/doc/install ) and set up your go
environment correctly. In particular, it is recommended to set the `$GOPATH`
environment variable and to add the go bin directory or directories
`${GOPATH//://bin:}/bin` to the `$PATH` . See the Go wiki entry for
[GOPATH ](https://github.com/golang/go/wiki/GOPATH ).
2019-12-05 09:11:38 +05:30
Next, [install Node.js with npm ](https://nodejs.org/en/download/ ) which is
required to build the JavaScript and CSS files. The minimum supported Node.js
2020-03-06 04:06:22 +05:30
version is {{< min-node-version > }} and the latest LTS version is recommended.
2019-12-05 09:11:38 +05:30
2019-02-12 21:52:01 +05:30
**Note**: When executing make tasks that require external tools, like
`make misspell-check` , Gitea will automatically download and build these as
2019-03-10 02:45:45 +05:30
necessary. To be able to use these, you must have the `"$GOPATH/bin"` directory
2019-02-12 21:52:01 +05:30
on the executable path. If you don't add the go bin directory to the
2019-03-10 02:45:45 +05:30
executable path, you will have to manage this yourself.
2019-02-12 21:52:01 +05:30
2020-03-05 06:07:19 +05:30
**Note 2**: Go version {{< min-go-version > }} or higher is required. However, it is recommended to
2019-02-12 21:52:01 +05:30
obtain the same version as our continuous integration, see the advice given in
2020-10-23 21:29:45 +05:30
< a href = '{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}' > Hacking on
2019-02-12 21:52:01 +05:30
Gitea< / a >
2017-11-27 03:14:32 +05:30
2020-12-08 10:22:26 +05:30
{{< toc > }}
2017-11-27 03:14:32 +05:30
## Download
2020-01-29 08:00:02 +05:30
First, we must retrieve the source code. Since, the advent of go modules, the
simplest way of doing this is to use git directly as we no longer have to have
2020-11-28 11:42:22 +05:30
gitea built from within the GOPATH.
2017-11-27 03:14:32 +05:30
2019-02-12 21:52:01 +05:30
```bash
2020-01-29 08:00:02 +05:30
git clone https://github.com/go-gitea/gitea
2017-11-27 03:14:32 +05:30
```
2020-01-29 08:00:02 +05:30
(Previous versions of this document recommended using `go get` . This is
no longer necessary.)
2019-02-12 21:52:01 +05:30
Decide which version of Gitea to build and install. Currently, there are
multiple options to choose from. The `master` branch represents the current
development version. To build with master, skip to the [build section ](#build ).
2017-11-27 03:14:32 +05:30
2018-01-09 04:18:42 +05:30
To work with tagged releases, the following commands can be used:
2019-02-12 21:52:01 +05:30
```bash
2017-11-27 03:14:32 +05:30
git branch -a
2019-08-23 07:25:06 +05:30
git checkout v{{< version > }}
2017-11-27 03:14:32 +05:30
```
2019-02-12 21:52:01 +05:30
To validate a Pull Request, first enable the new branch (`xyz` is the PR id;
for example `2663` for [#2663 ](https://github.com/go-gitea/gitea/pull/2663 )):
2017-11-27 03:14:32 +05:30
2019-02-12 21:52:01 +05:30
```bash
2017-11-27 03:14:32 +05:30
git fetch origin pull/xyz/head:pr-xyz
```
2019-08-23 07:25:06 +05:30
To build Gitea from source at a specific tagged release (like v{{< version > }}), list the
2019-02-12 21:52:01 +05:30
available tags and check out the specific tag.
2018-01-09 04:18:42 +05:30
List available tags with the following.
2017-11-27 03:14:32 +05:30
2019-02-12 21:52:01 +05:30
```bash
2017-11-27 03:14:32 +05:30
git tag -l
2019-08-23 07:25:06 +05:30
git checkout v{{< version > }} # or git checkout pr-xyz
2017-11-27 03:14:32 +05:30
```
## Build
2019-12-05 09:11:38 +05:30
To build from source, the following programs must be present on the system:
2020-03-05 06:07:19 +05:30
- `go` {{< min-go-version > }} or higher, see [here ](https://golang.org/dl/ )
2020-03-06 04:06:22 +05:30
- `node` {{< min-node-version > }} or higher with `npm` , see [here ](https://nodejs.org/en/download/ )
2020-10-23 21:29:45 +05:30
- `make` , see < a href = '{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make' > here</ a >
2019-12-05 09:11:38 +05:30
2019-02-12 21:52:01 +05:30
Various [make tasks ](https://github.com/go-gitea/gitea/blob/master/Makefile )
are provided to keep the build process as simple as possible.
2018-01-09 04:18:42 +05:30
Depending on requirements, the following build tags can be included.
2017-11-27 03:14:32 +05:30
2018-01-09 04:18:42 +05:30
* `bindata` : Build a single monolithic binary, with all assets included.
2019-02-12 21:52:01 +05:30
* `sqlite sqlite_unlock_notify` : Enable support for a
[SQLite3 ](https://sqlite.org/ ) database. Suggested only for tiny
installations.
* `pam` : Enable support for PAM (Linux Pluggable Authentication Modules). Can
be used to authenticate local users or extend authentication to methods
available to PAM.
2020-06-18 20:55:58 +05:30
Bundling assets into the binary using the `bindata` build tag is recommended for
production deployments. It is possible to serve the static assets directly via a reverse proxy,
but in most cases it is not necessary, and assets should still be bundled in the binary.
You may want to exclude bindata while developing/testing Gitea.
2019-12-05 09:11:38 +05:30
To include assets, add the `bindata` tag:
2019-02-12 21:52:01 +05:30
```bash
2019-12-05 09:11:38 +05:30
TAGS="bindata" make build
2019-02-12 21:52:01 +05:30
```
2017-11-27 03:14:32 +05:30
2019-03-10 02:45:45 +05:30
In the default release build of our continuous integration system, the build
2019-02-12 21:52:01 +05:30
tags are: `TAGS="bindata sqlite sqlite_unlock_notify"` . The simplest
recommended way to build from source is therefore:
2017-11-27 03:14:32 +05:30
2019-02-12 21:52:01 +05:30
```bash
2019-12-05 09:11:38 +05:30
TAGS="bindata sqlite sqlite_unlock_notify" make build
2017-11-27 03:14:32 +05:30
```
2020-02-22 14:45:11 +05:30
The `build` target is split into two sub-targets:
2020-03-05 06:07:19 +05:30
- `make backend` which requires [Go {{< min-go-version >}} ](https://golang.org/dl/ ) or greater.
2020-03-06 04:06:22 +05:30
- `make frontend` which requires [Node.js {{< min-node-version >}} ](https://nodejs.org/en/download/ ) or greater.
2020-02-22 14:45:11 +05:30
If pre-built frontend files are present it is possible to only build the backend:
```bash
TAGS="bindata" make backend
2020-02-26 23:58:39 +05:30
```
2020-02-22 14:45:11 +05:30
2017-11-27 03:14:32 +05:30
## Test
2019-03-10 02:45:45 +05:30
After following the steps above, a `gitea` binary will be available in the working directory.
2018-01-09 04:18:42 +05:30
It can be tested from this directory or moved to a directory with test data. When Gitea is
launched manually from command line, it can be killed by pressing `Ctrl + C` .
2017-11-27 03:14:32 +05:30
2019-02-12 21:52:01 +05:30
```bash
2017-11-27 03:14:32 +05:30
./gitea web
```
2019-04-29 23:38:21 +05:30
2020-08-18 16:51:24 +05:30
## Changing default paths
2019-04-29 23:38:21 +05:30
Gitea will search for a number of things from the `CustomPath` . By default this is
the `custom/` directory in the current working directory when running Gitea. It will also
look for its configuration file `CustomConf` in `$CustomPath/conf/app.ini` , and will use the
2019-10-18 05:21:31 +05:30
current working directory as the relative base path `AppWorkPath` for a number configurable
2020-08-08 19:32:22 +05:30
values. Finally the static files will be served from `StaticRootPath` which defaults to the `AppWorkPath` .
2019-04-29 23:38:21 +05:30
These values, although useful when developing, may conflict with downstream users preferences.
One option is to use a script file to shadow the `gitea` binary and create an appropriate
environment before running Gitea. However, when building you can change these defaults
using the `LDFLAGS` environment variable for `make` . The appropriate settings are as follows
* To set the `CustomPath` use `LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=custom-path\""`
* For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
2019-10-18 05:21:31 +05:30
* For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
2020-08-08 19:32:22 +05:30
* For `StaticRootPath` you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"`
2020-08-16 01:45:27 +05:30
* To change the default PID file location use `-X \"code.gitea.io/gitea/modules/setting.PIDFile=/run/gitea.pid\"`
2019-04-29 23:38:21 +05:30
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
with the appropriate `TAGS` as above.
Running `gitea help` will allow you to review what the computed settings will be for your `gitea` .
2020-04-11 08:43:31 +05:30
## Cross Build
The `go` compiler toolchain supports cross-compiling to different architecture targets that are supported by the toolchain. See [`GOOS` and `GOARCH` environment variable ](https://golang.org/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).
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).
Cross-build Gitea for Linux ARM64, without any tags:
```
GOOS=linux GOARCH=arm64 make build
```
Cross-build Gitea for Linux ARM64, with recommended build tags:
```
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
```
Replace `CC` , `GOOS` , and `GOARCH` as appropriate for your architecture target.