Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Gogs on Debian or Ubuntu
## Install Gogs v0.11.4 + Nginx Webserver + Mysql
## On Debian, Ubuntu 64Bits
## Author: Nilton OS --
## Version: 3.5
### Tested on Ubuntu 16.04 LTS 64Bits
### Tested on Debian 8/9 64Bits
echo ''
echo 'Support Ubuntu/Debian'
echo 'Installs Gogs 0.11.4'
echo 'Requires Ubuntu 16.04+, Debian 8+'
# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
echo "You must run the script as root or using sudo"
exit 1
MY_IP=$(ip a s|sed -ne '/!{s/^[ \t]*inet[ \t]*\([0-9.]\+\)\/.*$/\1/p}' | tr '\n' ' ')
echo -e "Set Server Name Ex: []: \c "
echo -e "Set Server IP Ex: $MY_IP []: \c "
echo "" >>/etc/hosts
echo "$SERVER_IP $SERVER_FQDN" >>/etc/hosts
hostnamectl set-hostname $SERVER_FQDN
echo "$SERVER_FQDN" > /proc/sys/kernel/hostname
apt-get update
apt-get install -y wget nginx git-core mysql-client mysql-server
adduser --disabled-login --gecos 'Gogs' git
cd /home/git
wget --no-check-certificate
tar -xvf linux_amd64.tar.gz && rm -f linux_amd64.tar.gz
echo -e "Set Password for Gogs in Mysql Ex: gogs_password : \c "
echo "Enter Mysql root password"
echo "CREATE USER 'gogs'@'localhost' IDENTIFIED BY $GOGS_PASS;" >>/home/git/gogs/scripts/mysql.sql
echo "GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost';" >>/home/git/gogs/scripts/mysql.sql
echo "--------------------"
mysql -p < /home/git/gogs/scripts/mysql.sql
chmod +x /home/git/gogs/gogs
mkdir -p /home/git/gogs/log
chown -R git:git /home/git/gogs
chown -R git:git /home/git/gogs/*
echo ""
echo "Setup Webserver Nginx"
echo "--------------------"
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
sed -i 's|mysqld.service|mysqld.service mysql.service|' /etc/systemd/system/gogs.service
systemctl daemon-reload
systemctl enable gogs.service
systemctl start gogs.service
echo 'server {
listen YOUR_SERVER_IP:80;
server_name YOUR_SERVER_FQDN;
proxy_set_header X-Real-IP $remote_addr; # pass on real client IP
location / {
proxy_pass http://localhost:3000;
}' > /etc/nginx/sites-available/gogs.conf
ln -s /etc/nginx/sites-available/gogs.conf /etc/nginx/sites-enabled/gogs.conf
sed -i "s/YOUR_SERVER_IP/$SERVER_IP/" /etc/nginx/sites-available/gogs.conf
sed -i "s/YOUR_SERVER_FQDN/$SERVER_FQDN/" /etc/nginx/sites-available/gogs.conf
service nginx restart
echo ""
echo "Gogs Server App run on port 3000, Nginx on port 80"
echo "Access http://$SERVER_FQDN to continue the installation"
echo ""
echo "Screencast Install:"
## Links

This comment has been minimized.

Copy link

jpfilevich commented Jun 13, 2017

This is great! Thanks.


This comment has been minimized.

Copy link
Owner Author

jniltinho commented Jun 19, 2017

@jpfilevich , Thanks !!! 👍 💯


This comment has been minimized.

Copy link

Gu1nness commented Jul 5, 2017


Nice script!

Just a little note though:
On debian 9 MySQL has been replaced by MariaDB (see
Thus, this script will fail when trying to install mysql-client and mysql-server.
However, a transition system has been created (from the link above):

For example, installing the metapackage default-mysql-server will install mariadb-server-10.1. Users who had mysql-server-5.5 or mysql-server-5.6 will have it removed and replaced by the MariaDB equivalent. Similarly, installing default-mysql-client will install mariadb-client-10.1.

It is possible to check the release with

if [[ $(lsb_release -c | grep buster) ]] then
    apt install -y wget nginx git-core mariadb-client mariadb-server
    apt install -y wget nginx git-core mysql-client mysql-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.