How to set up Gogs on Ubuntu 14.04

Introduction

Gogs is a self-hosted Git service written in Go. It is easy to run and has low system usage. It aspires to be the easiest, fastest, and easiest way to build self-hosted Git services.

At the end of this tutorial, you will have a running instance of Gogs, which includes a web interface, a management dashboard, and access to operations such as Git pull and push.

prerequisites

To follow this tutorial, you need:

Step 1-Install the database

In this step, we will create the backend Gogs database.

After logging in, please make sure your system software package is up to date.

sudo apt-get update

We will use MySQL as the backend server, and then install it. The -y flag here assumes that all prompts are.

sudo apt-get-y install mysql-server

During the installation process, the system will ask you to enter the password of the database root user. Make sure to use it safely, and remember it, because you will need it later in this tutorial.

Now create and open a file named gogs.sql. Here, we use the nano editor, but you can use your favorite text editor.

nano gogs.sql

Paste the following content into the file, then save and close it.

DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;

Finally, use MySQL to execute gogs.sql to create a Gogs database. Replace your_password with the root password you chose earlier in this step.

Note: There is no space between the -p sign and the password in this command.

mysql -u root -pyour_password < gogs.sql

To install Gogs from source code, you need to use version control tools such as Git and Mercurial, and then install them.

sudo apt-get-y install mercurial git

If you plan to clone the repository via SSH, you need a functioning SSH server, but fortunately, Ubuntu 14.04 provides a server out of the box.

Step 2-Install Go

Because Gogs is written in Go, we need to install it before compiling Gog.

First, we need to set some environment variables for Go. To do this, open the ~/.bashrc file for editing.

nano ~/.bashrc

Add the following line to the end of the file, then close and save.

export GOPATH=/home/git/go
export GOROOT=/usr/local/src/go
export PATH=${PATH}:$GOROOT/bin

Next, apply your changes.

source ~/.bashrc

Then use wget to download the latest compiled version of Go from its website. At the time of writing this article, the latest file is go1.4.2.linux-amd64.tar.gz.

wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz

Use tar to release the archive.

tar zxf go1.4.2.linux-amd64.tar.gz

Change the directory to the $GOROOT directory we defined in ~/.bashrc.

sudo mv go $GOROOT

Now, if you enter go in your terminal:

go

You should see something like this:

Go is a tool for managing Go source code.
​
Usage:
​
 go command [arguments]
​
...
​
Use "go help [topic]"for more information about that topic.

Step 3-Install and start Gogs as a service

Go has a built-in command get to easily download the source code of the Go project and all its dependencies. We will use it to download Gogs.

go get-d github.com/gogits/gogs

The source code of Gogs will now go to $GOPATH/src/github.com/gogits/gogs, so move there.

cd $GOPATH/src/github.com/gogits/gogs

Next, build and generate the binary file. This command may take some time to run.

go build

We will use Supervisor to manage the Gogs service.

First, let's install it.

sudo apt-get-y install supervisor

Let's create a Gogs daemon by creating a Supervisor configuration section. First, create a directory for log files.

sudo mkdir -p /var/log/gogs

Next, we will open the Supervisor configuration file for editing.

sudo nano /etc/supervisor/supervisord.conf

Append the following to the file to create the Gogs section.

[ program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"
user = git

This section defines the command we want to execute to start Gogs, use Supervisor to automatically start it, and specify the location of the log file and the corresponding environment variables.

Now restart Supervisor:

sudo service supervisor restart

We can use the following command to check if Gogs is running.

ps -ef | grep gogs

You should see output similar to this.

root      13441343008:55?00:00:00/home/git/go/src/github.com/gogits/gogs/gogs web

You can also verify that the server is running by viewing the stdout.log file.

tail /var/log/gogs/stdout.log

You should see a line like this:

2015 /03/0914:24:42[I] Gogs: Go Git Service 0.5.16.0301 Beta

You should also be able to access web pages with the URL of http://your_server_ip:3000/. This will redirect to the installation page, but it has not been filled out yet.

Step 4-Set Nginx as a reverse proxy

Let's continue to configure Nginx as a reverse proxy so that you can easily bind domain names to Gogs.

First, install Nginx.

sudo apt-get-y install nginx

Next, create an Nginx configuration file for gogs.

sudo nano /etc/nginx/sites-available/gogs

Add the following content and replace your_server_ip with the IP address of your Tencent CVM. If you are using the domain name of Tencent CVM, you can use your domain name here.

server {
 listen 80;
 server_name your_server_ip;
​
 proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP
​
 location /{
  proxy_pass http://localhost:3000;}}

And make a symbolic link to it so that Nginx can use it.

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs

Finally, restart Nginx to activate the virtual host configuration.

sudo service nginx restart

You should now be able to access web pages using URLvhttp://your_server_ip/ without specifying the port.

Step 5-Initialize Gogs

There is also a simple step to initialize Gogs during the first run.

Visit http://your_server_ip/install and fill in the following options. Many of these are already filled in for you, but make sure to replace the red variable with the server's value.

In the first part, Gogs requires MySQL, PostgreSQL or SQLite3, fill in:

In the second part, Gogs General Settings, fill in:

Skip the optional email and notification settings, then under "Administrator Account Settings", select the administrator username and password, and include your email address. We will set the admin username to your_admin_username in the next step.

Finally, click "Install Gogs" and log in.

Step 6-Test Gogs

You are all done! Let's do a simple pull/push test to ensure that Gogs is running properly.

First, go to http://your_server_ip/repo/create and create a repository named my-test-repo, then click on the "Use README.md to initialize this repository" option .

Now you should be able to clone it. First, go to your home directory.

cd

Next, clone the repository.

git clone http://your_server_ip/your_admin_username/my-test-repo.git

Switch to the repository directory.

cd my-test-repo

Update README.md.

echo 'I love Gogs!'>> README.md

Submit your changes and push them. This command will ask you for the username and password of Gogs.

git add --all && git commit -m "init commit"&& git push origin master

in conclusion

Now, if you go back to http://your_server_ip/your_admin_username/my-test-repo, you will see "I like Gogs!" appended to the README line. It's that simple!

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.


Reference: "How To Set Up Gogs on Ubuntu 14.04"

Recommended Posts

How to set up Gogs on Ubuntu 14.04
How to set up R on Ubuntu 14.04
How to set up Shiny Server on Ubuntu 14.04
How to set up time synchronization on Ubuntu 18.04
How to set up a DNS server on Ubuntu 18.04
How to set PostgreSQL startup on Ubuntu 16.04
How to set up Java Home on Ubuntu and Raspbian
How to set up a Masterless Puppet environment on Ubuntu 14.04
How to set up a firewall with UFW on Ubuntu 14.04
How to set up vsftpd for anonymous downloads on Ubuntu 16.04
How to set up a production Elasticsearch cluster on Ubuntu 14.04
How to set up an Apache virtual host on Ubuntu 16.04
How to set up an Apache virtual host on Ubuntu 20.04
How to set up password authentication with Nginx on Ubuntu 14.04
How to set up vsftpd for user directories on Ubuntu 16.04
How to set static IP on Ubuntu 18.04 Server
How to install and configure Gogs on Ubuntu 18.04
How to set static IP on Ubuntu 18.04 Server
How to set up SSH keys on CentOS 8
Explain how to set static IP on ubuntu14.04
How to set up Ghost one-click app for Ubuntu 16.04
How to set a fixed IP based on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04