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

from-source.en-us.md 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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: true
  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. **Note**: When executing make tasks that require external tools, like
  22. `make misspell-check`, Gitea will automatically download and build these as
  23. necessary. To be able to use these, you must have the `"$GOPATH/bin"` directory
  24. on the executable path. If you don't add the go bin directory to the
  25. executable path, you will have to manage this yourself.
  26. **Note 2**: Go version 1.11 or higher is required. However, it is recommended to
  27. obtain the same version as our continuous integration, see the advice given in
  28. <a href='{{< relref "doc/advanced/hacking-on-gitea.en-us.md" >}}'>Hacking on
  29. Gitea</a>
  30. ## Download
  31. First, retrieve the source code. The easiest way is to use the Go tool. Use the
  32. following commands to fetch the source and switch into the source directory.
  33. Go is quite opinionated about where it expects its source code, and simply
  34. cloning the Gitea repository to an arbitrary path is likely to lead to
  35. problems - the fixing of which is out of scope for this document.
  36. ```bash
  37. go get -d -u code.gitea.io/gitea
  38. cd "$GOPATH/src/code.gitea.io/gitea"
  39. ```
  40. Decide which version of Gitea to build and install. Currently, there are
  41. multiple options to choose from. The `master` branch represents the current
  42. development version. To build with master, skip to the [build section](#build).
  43. To work with tagged releases, the following commands can be used:
  44. ```bash
  45. git branch -a
  46. git checkout v1.0
  47. ```
  48. To validate a Pull Request, first enable the new branch (`xyz` is the PR id;
  49. for example `2663` for [#2663](https://github.com/go-gitea/gitea/pull/2663)):
  50. ```bash
  51. git fetch origin pull/xyz/head:pr-xyz
  52. ```
  53. To build Gitea from source at a specific tagged release (like v1.0.0), list the
  54. available tags and check out the specific tag.
  55. List available tags with the following.
  56. ```bash
  57. git tag -l
  58. git checkout v1.0.0 # or git checkout pr-xyz
  59. ```
  60. ## Build
  61. Since all required libraries are already bundled in the Gitea source, it's
  62. possible to build Gitea with no additional downloads apart from Make
  63. <a href='{{< relref "doc/advanced/make.en-us.md" >}}'>(See here how to get Make)</a>.
  64. Various [make tasks](https://github.com/go-gitea/gitea/blob/master/Makefile)
  65. are provided to keep the build process as simple as possible.
  66. Depending on requirements, the following build tags can be included.
  67. * `bindata`: Build a single monolithic binary, with all assets included.
  68. * `sqlite sqlite_unlock_notify`: Enable support for a
  69. [SQLite3](https://sqlite.org/) database. Suggested only for tiny
  70. installations.
  71. * `pam`: Enable support for PAM (Linux Pluggable Authentication Modules). Can
  72. be used to authenticate local users or extend authentication to methods
  73. available to PAM.
  74. Bundling assets into the binary using the `bindata` build tag can make
  75. development and testing easier, but is not ideal for a production deployment.
  76. To include assets, they must be built separately using the `generate` make
  77. task e.g.:
  78. ```bash
  79. TAGS="bindata" make generate build
  80. ```
  81. In the default release build of our continuous integration system, the build
  82. tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest
  83. recommended way to build from source is therefore:
  84. ```bash
  85. TAGS="bindata sqlite sqlite_unlock_notify" make generate build
  86. ```
  87. ## Test
  88. After following the steps above, a `gitea` binary will be available in the working directory.
  89. It can be tested from this directory or moved to a directory with test data. When Gitea is
  90. launched manually from command line, it can be killed by pressing `Ctrl + C`.
  91. ```bash
  92. ./gitea web
  93. ```
  94. ## Changing the default CustomPath, CustomConf and AppWorkDir
  95. Gitea will search for a number of things from the `CustomPath`. By default this is
  96. the `custom/` directory in the current working directory when running Gitea. It will also
  97. look for its configuration file `CustomConf` in `$CustomPath/conf/app.ini`, and will use the
  98. current working directory as the relative base path `AppWorkDir` for a number configurable
  99. values.
  100. These values, although useful when developing, may conflict with downstream users preferences.
  101. One option is to use a script file to shadow the `gitea` binary and create an appropriate
  102. environment before running Gitea. However, when building you can change these defaults
  103. using the `LDFLAGS` environment variable for `make`. The appropriate settings are as follows
  104. * To set the `CustomPath` use `LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=custom-path\""`
  105. * For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
  106. * For `AppWorkDir` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkDir=working-directory\"`
  107. Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
  108. with the appropriate `TAGS` as above.
  109. Running `gitea help` will allow you to review what the computed settings will be for your `gitea`.