Gogs is written in Go, please take A Tour of Go if you haven't done so!
- Environment
- Step 1: Install dependencies
- Step 2: Initialize your database
- Step 3: Get the code
- Step 4: Configure database settings
- Step 5: Start the server
- Other nice things
Gogs is built and runs as a single binary and meant to be cross platform. Therefore, you should be able to develop Gogs in any major platforms you prefer.
Gogs has the following dependencies:
- Git (v1.8.3 or higher)
- Go (v1.18 or higher)
- Less.js
- Task (v3)
- goimports
- go-mockgen
- Database upon your choice (pick one, we choose PostgreSQL in this document):
- PostgreSQL (v9.6 or higher)
- MySQL with
ENGINE=InnoDB
(v5.7 or higher) - SQLite3
- TiDB
-
Install Homebrew.
-
Install dependencies:
brew install go postgresql git npm go-task/tap/go-task npm install -g less npm install -g less-plugin-clean-css go install github.com/derision-test/go-mockgen/cmd/[email protected] go install golang.org/x/tools/cmd/goimports@latest
-
Configure PostgreSQL to start automatically:
brew services start postgresql
-
Ensure
psql
, the PostgreSQL command line client, is on your$PATH
. Homebrew does not put it there by default. Homebrew gives you the command to run to insertpsql
in your path in the "Caveats" section ofbrew info postgresql
. Alternatively, you can use the command below. It might need to be adjusted depending on your Homebrew prefix (/usr/local
below) and shell (bash below).hash psql || { echo 'export PATH="/usr/local/opt/postgresql/bin:$PATH"' >> ~/.bash_profile } source ~/.bash_profile
-
Add package repositories:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
-
Update repositories:
sudo apt-get update
-
Install dependencies:
sudo apt install -y make git-all postgresql postgresql-contrib golang-go nodejs npm install -g less go install github.com/go-task/task/v3/cmd/task@latest go install github.com/derision-test/go-mockgen/cmd/[email protected] go install golang.org/x/tools/cmd/goimports@latest
-
Configure startup services:
sudo systemctl enable postgresql
You need a fresh Postgres database and a database user that has full ownership of that database.
-
Create a database for the current Unix user:
# For Linux users, first access the postgres user shell sudo su - postgres
createdb
-
Create the Gogs user and password:
createuser --superuser gogs psql -c "ALTER USER gogs WITH PASSWORD '<YOUR PASSWORD HERE>';"
-
Create the Gogs database
createdb --owner=gogs --encoding=UTF8 --template=template0 gogs
Generally, you don't need a full clone, so set --depth
to 10
:
git clone --depth 10 https://github.com/gogs/gogs.git
NOTE The repository has Go modules enabled, please clone to somewhere outside of your $GOPATH
.
Create a custom/conf/app.ini
file inside the repository and put the following configuration (everything under custom/
directory is used to override default files and is excluded by .gitignore
):
[database]
TYPE = postgres
HOST = 127.0.0.1:5432
NAME = gogs
USER = gogs
PASSWORD = <YOUR PASSWORD HERE>
SSL_MODE = disable
The following command will start the web server and automatically recompile and restart the server if any Go files changed:
task web --watch
NOTE If you changed any file under conf/
, template/
or public/
directory, be sure to run task generate
afterwards!
When you are actively working on HTML templates and static files during development, you may want to enable the following configuration to avoid recompiling and restarting Gogs every time you make a change to files under template/
and public/
directories:
RUN_MODE = dev
[server]
LOAD_ASSETS_FROM_DISK = true
Sometimes you will want to develop Gogs but it just so happens you will be on a plane or a train or perhaps a beach, and you will have no WiFi. And you may raise your fist toward heaven and say something like, "Why, we can put a man on the moon, so why can't we develop high-quality Git hosting without an Internet connection?" But lower your hand back to your keyboard and fret no further, you can develop Gogs with no connectivity by setting the following configuration in your custom/conf/app.ini
:
[server]
OFFLINE_MODE = true