Setting Up a Personal Gogs Git Server
Well, if you're here you must be interested in running your own personal GitHub/GitLab right? I'll help you get close to that with gogs - the Go Git Service. This will probably take you less than 20 minutes to do. When you're done, you'll have a simple private git server just for yourself.
You must have a running server (local or remote) with git installed.
Create a sudo user named 'git'
This is the user that the gogs service will run under.
sudo adduser git # ENTER A PASSWORD # Then, keep hitting Enter for the other prompts # Add git to the sudoers group sudo adduser git sudo # Login as the git user su - git cd /home/git
The simplest way to get gogs is by downloading a binary from their site. Since you're in a server environment most likely, you'll probably use
wget. The code below assumes you're running a typical 64bit Ubuntu linux server.
# Download & extract gogs GOGS_FILE=gogs_v0.9.13_linux_amd64.tar.gz curl -O https://dl.gogs.io/$GOGS_FILE tar -xvzf $GOGS_FILE cd gogs
That's it! Now we just run gogs...
# Start gogs on localhost:3000 ./gogs web
After you run gogs, direct your browser to
http://[server_ip]:3000. You'll see the setup page.
Setting up gogs
For the database type, I simply chose SQLite3. I haven't had any problems with it so far, but you could choose MySQL or PostgreSQL instead. They might require extra setup.
With SQLite3 selected, you need to store the database somewhere. The default is
data/gogs.db but if you want to run gogs as a service (which we'll do later), they recommend absolute paths. So
/home/git/gogs/data/gogs.db it is.
Next, you can change the Application Name if you want to. The Repo Path and Run User options are pretty important. You can just keep the defaults if you setup the 'git' user above.
Domain is either your server's IP address or domain name. For example, either
gogs.jakedeichert.com would work here. SSH port is self-explanatory. The HTTP port I left as the gogs default of 3000. Since this is a personal server, I have no issue bookmarking
The Application URL is a string used throughout gogs for things such as clone urls. Use the same IP/domain and HTTP port from above. For the Log Path, leaving the default should be fine.
Now, the optional settings. We're going to skip the email section. It's a personal git server.. if you need to be notified when you push to your own repo, you may have something similar to the "fear of missing out" or legitimate security concerns.
For the server settings, we'll choose options that make sense for a personal server. Let's checkmark Disable Self-registration and Enable Require Sign In to View Pages. We don't want random people wasting our server resources. Also, if you don't plan on using Gravatar for yourself, disable that too. Note, you can upload your own image through profile settings later on.
Finally, create an admin account. This is the point where you open up INSERT PASSWORD MANAGER APP HERE and generate a password. You could even use that same app to generate a username, but your own name should suffice and is shorter to type most likely. Note, you do not need to enter an email address.
Click Install Gogs. Now you'll be redirected to your dashboard! If instead gogs gives you an error, you may have specified some directory paths that your user doesn't actually have access to.
Enabling Gogs as a service
I'm assuming you're running Ubuntu, so we'll enable gogs as an
# Press CTRL-C to stop the running gogs instance # Copy the gogs init file sudo cp scripts/init/debian/gogs /etc/init.d sudo chmod +x /etc/init.d/gogs
I was also still assuming that you are using the 'git' user you created earlier and that gogs is in the directory path
/home/git/gogs. If either is false, you'll need to edit that
init file to work with your setup.
Finally, start gogs as a service.
sudo service gogs start
Please keep in mind, right now all of your gogs traffic is unencrypted. Any code you pull or push could be viewed by others if you're on a public network.
You should look into setting up an SSL certificate with Let's Encrypt to ensure your traffic is properly protected.