You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

from-source.en-us.md 7.9 kB

Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. ---
  2. date: "2016-12-01T16:00:00+02:00"
  3. title: "Installation from source"
  4. slug: "install-from-source"
  5. weight: 10
  6. toc: false
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "installation"
  11. name: "From source"
  12. weight: 30
  13. identifier: "install-from-source"
  14. ---
  15. # Installation from source
  16. You should [install go](https://golang.org/doc/install) and set up your go
  17. environment correctly. In particular, it is recommended to set the `$GOPATH`
  18. environment variable and to add the go bin directory or directories
  19. `${GOPATH//://bin:}/bin` to the `$PATH`. See the Go wiki entry for
  20. [GOPATH](https://github.com/golang/go/wiki/GOPATH).
  21. Next, [install Node.js with npm](https://nodejs.org/en/download/) which is
  22. required to build the JavaScript and CSS files. The minimum supported Node.js
  23. version is {{< min-node-version >}} and the latest LTS version is recommended.
  24. **Note**: When executing make tasks that require external tools, like
  25. `make misspell-check`, Gitea will automatically download and build these as
  26. necessary. To be able to use these, you must have the `"$GOPATH/bin"` directory
  27. on the executable path. If you don't add the go bin directory to the
  28. executable path, you will have to manage this yourself.
  29. **Note 2**: Go version {{< min-go-version >}} or higher is required. However, it is recommended to
  30. obtain the same version as our continuous integration, see the advice given in
  31. <a href='{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}'>Hacking on
  32. Gitea</a>
  33. **Table of Contents**
  34. {{< toc >}}
  35. ## Download
  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. ```bash
  40. git clone https://github.com/go-gitea/gitea
  41. ```
  42. (Previous versions of this document recommended using `go get`. This is
  43. no longer necessary.)
  44. Decide which version of Gitea to build and install. Currently, there are
  45. multiple options to choose from. The `master` branch represents the current
  46. development version. To build with master, skip to the [build section](#build).
  47. To work with tagged releases, the following commands can be used:
  48. ```bash
  49. git branch -a
  50. git checkout v{{< version >}}
  51. ```
  52. To validate a Pull Request, first enable the new branch (`xyz` is the PR id;
  53. for example `2663` for [#2663](https://github.com/go-gitea/gitea/pull/2663)):
  54. ```bash
  55. git fetch origin pull/xyz/head:pr-xyz
  56. ```
  57. To build Gitea from source at a specific tagged release (like v{{< version >}}), list the
  58. available tags and check out the specific tag.
  59. List available tags with the following.
  60. ```bash
  61. git tag -l
  62. git checkout v{{< version >}} # or git checkout pr-xyz
  63. ```
  64. ## Build
  65. To build from source, the following programs must be present on the system:
  66. - `go` {{< min-go-version >}} or higher, see [here](https://golang.org/dl/)
  67. - `node` {{< min-node-version >}} or higher with `npm`, see [here](https://nodejs.org/en/download/)
  68. - `make`, see <a href='{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make'>here</a>
  69. Various [make tasks](https://github.com/go-gitea/gitea/blob/master/Makefile)
  70. are provided to keep the build process as simple as possible.
  71. Depending on requirements, the following build tags can be included.
  72. - `bindata`: Build a single monolithic binary, with all assets included.
  73. - `sqlite sqlite_unlock_notify`: Enable support for a
  74. [SQLite3](https://sqlite.org/) database. Suggested only for tiny
  75. installations.
  76. - `pam`: Enable support for PAM (Linux Pluggable Authentication Modules). Can
  77. be used to authenticate local users or extend authentication to methods
  78. available to PAM.
  79. * `gogit`: (EXPERIMENTAL) Use go-git variants of git commands.
  80. Bundling assets into the binary using the `bindata` build tag is recommended for
  81. production deployments. It is possible to serve the static assets directly via a reverse proxy,
  82. but in most cases it is not necessary, and assets should still be bundled in the binary.
  83. You may want to exclude bindata while developing/testing Gitea.
  84. To include assets, add the `bindata` tag:
  85. ```bash
  86. TAGS="bindata" make build
  87. ```
  88. In the default release build of our continuous integration system, the build
  89. tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest
  90. recommended way to build from source is therefore:
  91. ```bash
  92. TAGS="bindata sqlite sqlite_unlock_notify" make build
  93. ```
  94. The `build` target is split into two sub-targets:
  95. - `make backend` which requires [Go {{< min-go-version >}}](https://golang.org/dl/) or greater.
  96. - `make frontend` which requires [Node.js {{< min-node-version >}}](https://nodejs.org/en/download/) or greater.
  97. If pre-built frontend files are present it is possible to only build the backend:
  98. ```bash
  99. TAGS="bindata" make backend
  100. ```
  101. ## Test
  102. After following the steps above, a `gitea` binary will be available in the working directory.
  103. It can be tested from this directory or moved to a directory with test data. When Gitea is
  104. launched manually from command line, it can be killed by pressing `Ctrl + C`.
  105. ```bash
  106. ./gitea web
  107. ```
  108. ## Changing default paths
  109. Gitea will search for a number of things from the `CustomPath`. By default this is
  110. the `custom/` directory in the current working directory when running Gitea. It will also
  111. look for its configuration file `CustomConf` in `$CustomPath/conf/app.ini`, and will use the
  112. current working directory as the relative base path `AppWorkPath` for a number configurable
  113. values. Finally the static files will be served from `StaticRootPath` which defaults to the `AppWorkPath`.
  114. These values, although useful when developing, may conflict with downstream users preferences.
  115. One option is to use a script file to shadow the `gitea` binary and create an appropriate
  116. environment before running Gitea. However, when building you can change these defaults
  117. using the `LDFLAGS` environment variable for `make`. The appropriate settings are as follows
  118. - To set the `CustomPath` use `LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=custom-path\""`
  119. - For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
  120. - For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
  121. - For `StaticRootPath` you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"`
  122. - To change the default PID file location use `-X \"code.gitea.io/gitea/modules/setting.PIDFile=/run/gitea.pid\"`
  123. Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
  124. with the appropriate `TAGS` as above.
  125. Running `gitea help` will allow you to review what the computed settings will be for your `gitea`.
  126. ## Cross Build
  127. 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).
  128. 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).
  129. Cross-build Gitea for Linux ARM64, without any tags:
  130. ```
  131. GOOS=linux GOARCH=arm64 make build
  132. ```
  133. Cross-build Gitea for Linux ARM64, with recommended build tags:
  134. ```
  135. CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
  136. ```
  137. Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target.