Setting up a Go droplet in Digital Ocean

Abhinav Rai
2 min readSep 24, 2020

First, ssh into the digitalocean box | ssh root@

1. Add key to Gitlab / Github so that you can clone the project in your repo and pull when you make a change.

ssh-keygen -t ed25519 -C "<comment>"vim /root/.ssh/

Add this key to gitlab

Clone the repo

2. Install Go

curl -O xvf go1.15.2.linux-amd64.tar.gzchown -R root:root ./gomv go /usr/local
vim ~/.bashrc
(Add the below export commands)
export GOPATH=$HOME/workexport PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
source ~/.bashrcgo version

3. Install Nginx

apt updateapt install nginxsystemctl status nginx
vim /etc/nginx/sites-enabled/default# Add this in the location blockproxy_pass http://localhost:8080;proxy_http_version 1.1;

4. Create a systemd service for your server

cd /etc/systemd/system/touch name.service# Copy the below service code by changing location[Unit]Description= instance to start[Service]User=rootGroup=www-dataWorkingDirectory=/root/{name}Restart=on-failureRestartSec=5sExecStart=/root/indra/out/{name} server[Install]

5. Install Build Essentials for Go to run

apt-get updateapt-get install build-essential

6. Install make (If you are using makefile)

apt install make

7. Install Postgres (or any db | Below points are for postgres)

apt install postgresql postgresql-contribsudo -u postgres psqlcreate user abhi with password 'password';alter role abhi superuser;

8. Run / Restart services

systemctl start name.service
systemctl restart nginx.service

9. Setting up ulimit (increasing file descriptors, 1024 by default)
Making it 65535 to avoid socket: too many open files error

# available limit
user@ubuntu:~$ ulimit -n

# To increase the available limit to say 65535
user@ubuntu:~$ sudo vim /etc/sysctl.conf

# add the following line to it
fs.file-max = 65535

# run this to refresh with new config
user@ubuntu:~$ sudo sysctl -p
# edit the following file
user@ubuntu:~$ sudo vim /etc/security/limits.conf

# add following lines to it
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535

# edit the following file
user@ubuntu:~$ sudo vim /etc/pam.d/common-session

# add this line to it
session required

# logout and login and try the following command
user@ubuntu:~$ ulimit -n



Abhinav Rai

Buliding Engagebud | Guitarist | Traveller | Entrepreneur