DEV Community

Nivethan
Nivethan

Posted on • Originally published at krowemoh.com

Setting Up Gitea on AlmaLinux 9

I've started using github and gitea issues recently and I quite like it as a way to keep track of things I want to do. Thus I want to set up gitea for my private projects as I don't want that stuff getting exposed to github.

The docs for gitea seem to be a bit too wordy for my taste so I'm going to document the simplified instructions here. It's also very possible I just missed the simplified documentation somehow. I had set it up before but hadn't documented the process then.

Gitea documentation

These instructions are for Linux, specifically RHEL and it's clones.

Creating the User

Create the gitea user and give them sudo privileges:

sudo useradd -c "Gitea User" -G wheel -s /bin/bash gitea
Enter fullscreen mode Exit fullscreen mode

Get the Binary

Get the gitea binary:

wget -O gitea https://dl.gitea.com/gitea/1.23.1/gitea-1.23.1-linux-amd64
Enter fullscreen mode Exit fullscreen mode

Make it executable:

chmod +x gitea
Enter fullscreen mode Exit fullscreen mode

Install Gitea

The gitea installation is done via the browser, you may need to open port 3000 on the firewall as the web application runs on that port. On RHEL and it's dupes this will be done via firewall-cmd.

First move the gitea binary to /usr/local/bin:

sudo mv gitea /usr/local/bin
sudo chown root:root /usr/local/bin/gitea
sudo restorecon -Rv /usr/local/bin/gitea
Enter fullscreen mode Exit fullscreen mode

This will switch gitea to be owned by root and it will also correct the selinux context. The original context was that it could only run under the home directory of the person that downloaded it. However after moving it, we will need to enable to to be run from anywhere.

Run the binary:

gitea
Enter fullscreen mode Exit fullscreen mode

This should result in some message sbeing printed to the screen:

...
Starting Gitea on PID: 119828
...
[I] Listen: http://0.0.0.0:3000
...
Enter fullscreen mode Exit fullscreen mode

Now we can open the browser to http://server.ip.addr.ess:3000 and go through the installation process.

The settings can be left as default, the only thing I changed was the database type. I set it to use sqlite3 with the hope that migrating and backing up things becomes trivial.

Clicking Install Gitea will start the installation which for me took a second. The page doesn't appear to be doing anything but be patient, it is trucking away.
Once it's finished installing, you should be at the login page.

Register a User

At the login page, you can register a new user. The e-mail is mandatory as git requires it, though git allows a blank e-mail which gitea doesn't allow.

The solution to this is to use fake e-mails.

The password also has a requirement of being 8 characters which is kind of annoying but cest la vie.

Once the user is created, you should be at the main gitea page.

Running it as Service

The final step is to have gitea run as a service. For this gitea has a service file that one can copy and modify:

Gitea systemd unit file

The service file that I'm using is:

[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target

[Service]
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/home/gitea/
ExecStart=/usr/local/bin/gitea web --config /home/gitea/custom/conf/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/home/gitea

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

The big difference is that I created a user called gitea and have everything located under that user's home directory. The goal is to migrations in the future easier and to make sure that I know where the repos are living.

Copy the service file to /etc/systemd/system/ so that we can use systemd to amange the service.

Now if you do:

systemctl start gitea.service
Enter fullscreen mode Exit fullscreen mode

This should result in an error where the file is not found.

This is because the file was created with a different selinux context than it needs, to correct the context we can use the restorecon command.

/sbin/restorecon -v /etc/systemd/system/gitea.service
Enter fullscreen mode Exit fullscreen mode

With that done, we can now do:

systemctl start gitea
Enter fullscreen mode Exit fullscreen mode

If everything went well and we can see the gitea homepage, we can enable the service to run on boot.

systemctl enable gitea
Enter fullscreen mode Exit fullscreen mode

With that we are done! Gitea is installed and running as a service,

Troubleshooting

If you are having issues getting the service to run, the first step is to see if selinux is indeed getting in the way:

sudo setenforce 0
Enter fullscreen mode Exit fullscreen mode

Try running the service and if it does run, then it is an issue with selinux and the security contexts.

Top comments (0)