2023-07-18 13:20:19 -04:00
---
title: 'Compiling from source'
license: 'Apache-2.0'
2024-02-24 15:20:29 -05:00
origin_url: 'https://github.com/go-gitea/gitea/blob/d3982bcd814bac93e3cbce1c7eb749b17e413fbd/docs/content/installation/from-source.en-us.md'
2023-07-18 13:20:19 -04:00
---
2023-08-05 06:48:30 -04:00
## Installation from source
2023-07-18 13:20:19 -04:00
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 ).
2023-09-12 07:09:48 -04:00
Next, [install Node.js with npm ](https://nodejs.org/en/download/current ) which is
2023-07-18 13:20:19 -04:00
required to build the JavaScript and CSS files. The minimum supported Node.js
2023-09-12 07:09:48 -04:00
version is 20.
2023-07-18 13:20:19 -04:00
**Note**: When executing make tasks that require external tools, like
`make misspell-check` , Forgejo will automatically download and build these as
necessary. To be able to use these, you must have the `"$GOPATH/bin"` directory
2024-02-03 12:59:08 -05:00
on the executable path.
2023-07-18 13:20:19 -04:00
2024-02-03 12:59:08 -05:00
**Note 2**: Go version 1.21 or higher is required. However, it is recommended to
2023-08-17 13:01:23 -04:00
obtain the same version as the [continuous integration ](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/.forgejo/workflows/testing.yml ).
2023-07-18 13:20:19 -04:00
2023-11-30 03:43:55 -05:00
**Note 3**: If you want to avoid installing build dependencies manually,
you can also [build the Docker image ](#build-the-docker-image ), which runs
the build process in a Docker image containing all the required dependencies.
2023-08-05 06:48:30 -04:00
### Download
2023-07-18 13:20:19 -04:00
2024-02-03 12:59:08 -05:00
First, we must retrieve the source code.
2023-07-18 13:20:19 -04:00
```bash
git clone https://codeberg.org/forgejo/forgejo
```
Decide which version of Forgejo to build and install. Currently, there are
multiple options to choose from. The `forgejo` branch represents the current
development version.
To work with tagged releases, the following commands can be used:
```bash
git branch -a
2023-08-09 16:32:54 -04:00
git checkout v1.21.2-0
2023-07-18 13:20:19 -04:00
```
2023-08-09 16:32:54 -04:00
To build Forgejo from source at a specific tagged release (like v1.21.2-0), list the
2023-07-18 13:20:19 -04:00
available tags and check out the specific tag.
List available tags with the following.
```bash
git tag -l
2023-08-09 16:32:54 -04:00
git checkout v1.21.2-0
2023-07-18 13:20:19 -04:00
```
2023-08-05 06:48:30 -04:00
### Build
2023-07-18 13:20:19 -04:00
To build from source, the following programs must be present on the system:
2024-02-03 12:59:08 -05:00
- `go` v1.21 or higher, see [here ](https://golang.org/dl/ )
2023-09-12 07:09:48 -04:00
- `node` 20 or higher with `npm` , see [here ](https://nodejs.org/en/download/current )
2023-07-18 13:20:19 -04:00
- `make`
2024-02-03 12:59:08 -05:00
There are a number of useful `make` targets, only some of which are documented here.
They can all be displayed with:
```sh
$ make help
Make Routines:
- "" equivalent to "build"
- build build everything
- frontend build frontend files
- backend build backend files
- watch watch everything and continuously rebuild
- watch-frontend watch frontend files and continuously rebuild
- watch-backend watch backend files and continuously rebuild
...
```
2023-07-18 13:20:19 -04:00
Depending on requirements, the following build tags can be included.
- `bindata` : Build a single monolithic binary, with all assets included. Required for production build.
- `sqlite sqlite_unlock_notify` : Enable support for a
[SQLite3 ](https://sqlite.org/ ) database. Suggested only for small
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.
Using the `bindata` build tag is required for production
deployments. You could exclude `bindata` when you are
developing/testing Forgejo or able to separate the assets correctly.
To include all assets, use the `bindata` tag:
```bash
TAGS="bindata" make build
```
In the default release build of the continuous integration system, the build
tags are: `TAGS="bindata sqlite sqlite_unlock_notify"` . The simplest
recommended way to build from source is therefore:
```bash
TAGS="bindata sqlite sqlite_unlock_notify" make build
```
The `build` target is split into two sub-targets:
2024-02-03 12:59:08 -05:00
- `make backend` which requires [Go v1.21 ](https://golang.org/dl/ ) or greater.
2023-09-12 07:09:48 -04:00
- `make frontend` which requires [Node.js 20 ](https://nodejs.org/en/download/current ) or greater.
2023-07-18 13:20:19 -04:00
If pre-built frontend files are present it is possible to only build the backend:
```bash
TAGS="bindata" make backend
```
Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
2023-11-30 03:43:55 -05:00
### Build the Docker image
To build Forgejo's Docker image, you need to have Docker and the Docker Buildx plugin installed.
You can build the Docker image with:
```bash
2024-03-06 01:31:31 -05:00
docker buildx build --output type=docker --tag forgejo:mybuild .
2023-11-30 03:43:55 -05:00
```
This will run the entire build process in a Docker container with the required dependencies.
You can also supply a tag during the build process with the `-t` option, to make it easier to publish or run the image later.
2024-02-21 13:51:05 -05:00
### Testing
2023-07-18 13:20:19 -04:00
2024-02-21 13:51:05 -05:00
See [the section dedicated to testing ](./testing/ ).