Deploy Django Application using NGINX, uWSGI

After developing couple of django application and testing them using inbuild development server (runserver), I was ready to deploy my Django application to VPS but littile did I know, deployment of django application is a big task itself.

I first started using official tutorial from Digital Ocean How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04 but it turned out to be two complex. I spent almost a day but I ended up nowhere. I was searching for otherway of deployment thats when I came across uWSGI. You can find official documentation here. Setting up Django using uWSGI was not cakewalk either but I found it easy as compared to Gunicorn. In this effort, i spent almost two days (not whole days, may be  hours in total) but finally I got it working. I am documenting step by step actions for you to help.

Step#1 Prepare environment

$sudo apt-get update
$sudo apt-get upgrade
$sudo python3.6 -m pip install virtualenv

Now let us create a django application on server. If you have already developed your application, you can deploy it to server using git as explained here or copy code using FileZilla or some other ways. For simplicity, I am creating an application.

$django-admin startproject yourapp
$cd yourapp
$python3.6 manage.py startapp blog
$virtualenv venvft
created virtual environment CPython3.6.4.final.0-64 in 453ms
creator CPython3Posix(dest=/var/www/yourapp/venvft, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/user/.local/share/virtualenv/seed-app-data/v1.0.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

$source venvft/bin/activate
$pip install django 
$pip install psycopg2
deactivate

Please note the packages are installed inside virtual environment using pip install but outside it using command $sudo python3.6 -m pip install psycopg2. This command will not work inside virtual environment. Please don’t ask me why, I only know how. You can deactivate virtual environment at this stage.

Step#2 Django Application set up.

You already know what you need to do to set up django application. Changes to settings.py etc. For more details, you can refer to this post Building blog application using django.

Once basic setup is done, you need to run following commands

$ python3.6 manage.py makemigrations blog
$ python3.6 manage.py migrate

Before we test the application, please update ALLOWED_HOSTS in settings.py. Here ‘NNN.NN.NN.NNN’ stands for your server ip

ALLOWED_HOSTS = ['NNN.NN.NN.NNN','www.domain.com','domain.com','localhost','127.0.0.1','0.0.0.1']

Once done, let us test our application using our old development server. This is to ensure, our application is working fine. If you face any issue at this stage, it has nothing to do with server setup, tourbleshoot any Django related issue here. Only if you can run your application on development server, proceed to next step

python3.6 manage.oy runserver

You can open new command prompt and test this using following

curl http://127.0.0.1:8000/

Step#3 Run using uWSGI server

Now lets run it using uwsgi using following command

sudo uwsgi --http 0.0.0.0:8000 --home /var/www/yourapp/venvft --chdir /var/www/yourapp/yourapp --wsgi-file /var/www/yourapp/yourapp/wsgi.py

Toubleshooting. There is possibility that you might get below error

ModuleNotFoundError: No module named 'yourapp'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 28959, cores: 

In this case, you need to make few changes to yourapp/yourapp/uwsgi.py file

import os
import sys #added this

from django.core.wsgi import get_wsgi_application

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #added this
sys.path.append(BASE_DIR) #added this

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yourapp.settings')

application = get_wsgi_application()

I have added comments about which line needs to be added. Now test again and it should work file.

Step# 4 uWSGI setup

Create a yourapp.ini file @ location /home/username/uwsgi/sites as below

[uwsgi]
home = /var/www/yourapp/venvft
chdir = /var/www/yourapp/yourapp
wsgi-file = /var/www/yourapp/yourapp/wsgi.py

#http = 0.0.0.0:8000

socket = /run/uwsgi/yourapp.sock
vacuum = true
chown-socket = username:www-data
chmod-socket = 666

Please change yourapp and username in this file as pr your names

Now cd /etc/systemd/system/ and sudo nano uwsgi.service

[Unit]
#Description=uWSGI Emperor service
Description=uWSGI Emperor

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown username:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /home/username/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Here also. change the username to match yours.

After this is done cd /var/www/ and change ownership of project folder

sudo chown www-data:www-data -R yourapp

Step#5 NGINX setup

This is simplest of all. Simply use following code.

server {
    server_name yourdomain.com www.yourdomain.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/yourapp.sock;
        }
}

Now run following commands

sudo service nginx stop
sudo service uwsgi stop
sudo service nginx start
sudo service uwsgi start

Restart can also work but I prefer to stop and start.

Now before you check your application on your browser cd /run/uwsgi
and check if this folder has any files

If there is no error you will see filename yourapp.sock. Now you are all set to access your application using its domain name.

Following links were very helpful for me. If you need any clarification or facing error, you can let me know or check below links

 

How to Install and Configure Elasticsearch on Ubuntu

Elasticsearch is a distributed, open source search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is built on Apache Lucene and was first released in 2010 by Elasticsearch N.V. . Elasticsearch is the central component of the Elastic Stack, a set of open source tools for data ingestion, enrichment, storage, analysis, and visualization. Commonly referred to as the ELK Stack (after Elasticsearch, Logstash, and Kibana).

Elasticsearch is known for its simple REST APIs, distributed nature, speed, and scalability. You can use http methods like get , post, put, delete in combination with an url to manipulate your data.

Prerequisites

Elasticsearch is developed in java and you need to have java installed on your Ubuntu. Use following command to check if java is installed and its version.

$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode, sharing)

Now check if  $JAVA_HOME variable is configured by checking its content by following command. If it returns blank, you need to set it up. Check post How to set Java environment path $JAVA_HOME in Ubuntu for setting up $JAVA_HOME

$ echo $JAVA_HOME
/usr/java/java-1.11.0-openjdk-amd6

Setting up Elasticsearch

Packages is signed with the Elasticsearch Signing Key. Download and install the public signing key:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

You may need to install the apt-transport-https package on Ubuntu before proceeding

$sudo apt-get install apt-transport-https
Reading package lists... Done
Building dependency tree 
Reading state information... Done
apt-transport-https is already the newest version (1.6.12).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded./code>

Now Save the repository definition to /etc/apt/sources.list.d/elastic-7.x.list:

$ echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
deb https://artifacts.elastic.co/packages/7.x/apt stable main

You can install the Elasticsearch Debian package with:

sudo apt-get update 
sudo apt-get install elasticsearch

Configure Elasticsearch

Elasticsearch files are located in directory /etc/elasticsearch. There are two files

  1. elasticsearch.yml configures the Elasticsearch server settings.
  2. logging.yml it provides configuration for logging

Let us update elasticsearch.yml

sudo nano /etc/elasticsearch/elasticsearch.yml

There are multiple variables, however you need to update following variables

  • cluster.name : specifies the name of the cluster
  • node.name: specifies the name of the server (node) . Please note the double inverted commas.

Please do not change network.host. You might see that in some posts people have changed network.host 0.0.0.0 or 127.0.0.1. If you change network.host, The cluster coordination algorithm has changed in 7.0 610 and in order to be safe it requires some specific configuration. This is relaxed when you bind to localhost only, but if/when you change network.host elasticsearch enforces that your configure the cluster safely.

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: mycluster1
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: "node-1"
#
# Add custom attributes to the node:
#
#node.attr.rack: r1


...

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#

Launch Elasticsearch

You can start and stop Elasticsearch using following command

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

Testing Elasticsearch

You can check connectivity using curl. Install curl if you dont have it on your machine and run following command

$ curl -X GET "http://localhost:9200/?pretty"
{
  "name" : "node-1",
  "cluster_name" : "mycluster1",
  "cluster_uuid" : "Q6GqVVJfRZO6KSHQ-pFbcQ",
  "version" : {
    "number" : "7.5.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96",
    "build_date" : "2019-12-16T22:57:37.835892Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

How to set Java environment path $JAVA_HOME in Ubuntu

Java  based environment requires java installed on your system. Please check post how to install Java on ubuntu for installation. Sometimes even after installation of Java, environment variables are not set and this might have adverse impact on Java based software.

  1. Check if Java is installed

You can check if Java is install ed by following command

$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode, sharing)
  1. Check if $JAVA_HOME variable is set
$ echo $JAVA_HOME

If it returns blank,it means its not set up.

  1. Check Java directory.

Java is installed in directory /usr/lib/jvm in Ubuntu

$cd /usr/lib/jvm
:/usr/lib/jvm$ ls -la
total 16
drwxr-xr-x   3 root root 4096 Dec 19 23:22 .
drwxr-xr-x 133 root root 4096 Dec 25 23:36 ..
lrwxrwxrwx   1 root root   25 Feb 20  2019 default-java -> java-1.11.0-openjdk-amd64
lrwxrwxrwx   1 root root   21 Jul 18 23:51 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
-rw-r--r--   1 root root 1994 Oct 17 03:31 .java-1.11.0-openjdk-amd64.jinfo
drwxr-xr-x   7 root root 4096 Dec 19 23:22 java-11-openjdk-amd
  1. Setting up the $JAVA_HOME value

Open terminal and type following

$export JAVA_HOME=/usr/java/java-1.11.0-openjdk-amd64

You need to replace java-1.11.0-openjdk-amd64 with <your java version>

Now check the content of $JAVA_HOME by typing below

$$ echo $JAVA_HOME
/usr/java/java-1.11.0-openjdk-amd6

Variable $JAVA_HOME is case sensitive so make sure you check and set correct variable.

How to set up FileZilla to connect to Digital Ocean Droplet

FileZilla is a free software, cross-platform FTP application, consisting of FileZilla Client and FileZilla Server.  Setting up FileZilla to access your Digital Ocean droplet is very easy. There are multiple ways to access it e.g. FTP, SFTP, using interactive mode, entering password everytime using keyfile etc. We will use simplest method, using SFTP and entering password everytime we try to login.

Step#1 Install FileZilla

Please refer to How to Install FileZilla on Ubuntu post

Step#2 Start FileZilla

Once you start the application, you will see below screen

Step#3 Go to File->Site Manager

Step#4 Set up “New Site”

  • Host” – you can find this information at your hosting provider. You can get ip by using following command ping <domainname.com>
  • Port” – You can leave this black, if you chose FTP, it will automatically select 21 and if you select SFTP, it will select 22.
  • Protocol” – protocol for exchanging files over any network. Please select”SFTP-SSH File Transfer Protocol”
  • Logon Type” – You can select whichever logon type is convenient to you. For now, please select “Ask for password”
  • User: The username having required access
  • Password: password


Don’t worry about any other tabs as of now.

Once done, clock on “Connect” and you will get connected to your Digital Ocean Droplet.

If you get any issue, please do let me know

How to Install GNU Paint on Ubuntu

GNU Paint (gpaint) is a simple, easy-to-use paint program for GNOME, the GNU Desktop. Gpaint starts as a port of xpaint and takes advantages of features unique to the GNOME environment. Gpaint is licensed under the GNU GPL, version 2 or later.

Current Features:

  • Drawing tools–ovals, freehand, polygon, text, with fill or shallow for polygons and closed freehand.
  • Cut and paste by selecting irregular regions or polygons.
  • Print support using gnome-print (still flaky, will be improved upon next release)
  • Modern, easy-to-use user interface with tool and color palettes
  • Editing multiple images at the same time without running multiple instances of the image editor
  • All image processing features present in xpaint

Installation

To install it type following command on terminal


$ sudo apt-get install gpaint

output


[sudo] password for USERNAME:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libglade2-0
The following NEW packages will be installed:
gpaint libglade2-0
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 161 kB of archives.
After this operation, 915 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libglade2-0 amd64 1:2.6.4-2 [44.6 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 gpaint amd64 0.3.3-6.1build1 [117 kB]
Fetched 161 kB in 10s (15.4 kB/s)
Selecting previously unselected package libglade2-0:amd64.
(Reading database ... 164728 files and directories currently installed.)
Preparing to unpack .../libglade2-0_1%3a2.6.4-2_amd64.deb ...
Unpacking libglade2-0:amd64 (1:2.6.4-2) ...
Selecting previously unselected package gpaint.
Preparing to unpack .../gpaint_0.3.3-6.1build1_amd64.deb ...
Unpacking gpaint (0.3.3-6.1build1) ...
Setting up libglade2-0:amd64 (1:2.6.4-2) ...
Setting up gpaint (0.3.3-6.1build1) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

Once installation is done you can find gpaint in list of installed application and its ready to use. Here is screenshot of gpaint

How to Install FileZilla on Ubuntu

Installing FileZilla on Ubuntu is very easy, simply follow below steps

Step#1 Update the system


$ sudo apt-get update
[sudo] password for user:
Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Fetched 252 kB in 17s (15.3 kB/s)
Reading package lists... Done

Step#2 Install FileZilla


$ sudo apt-get install filezilla
[sudo] password for iser: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  filezilla-common libfilezilla0 libpugixml1v5 libwxbase3.0-0v5 libwxgtk3.0-0v5
The following NEW packages will be installed:
  filezilla filezilla-common libfilezilla0 libpugixml1v5 libwxbase3.0-0v5 libwxgtk3.0-0v5
0 upgraded, 6 newly installed, 0 to remove and 1 not upgraded.
Need to get 9,359 kB of archives.
After this operation, 38.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 filezilla-common all 3.28.0-1 [2,301 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libfilezilla0 amd64 0.11.0-1 [48.3 kB]                                                                                                            
Get:3 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libpugixml1v5 amd64 1.8.1-7 [82.8 kB]                                                                                                             
Get:4 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libwxbase3.0-0v5 amd64 3.0.4+dfsg-3 [954 kB]                                                                                                      
Get:5 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 libwxgtk3.0-0v5 amd64 3.0.4+dfsg-3 [4,182 kB]                                                                                                     
Get:6 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 filezilla amd64 3.28.0-1 [1,791 kB]                                                                                                               
Fetched 9,359 kB in 27s (345 kB/s)                                                                                                                                                                                
Selecting previously unselected package filezilla-common.
(Reading database ... 163752 files and directories currently installed.)
Preparing to unpack .../0-filezilla-common_3.28.0-1_all.deb ...
Unpacking filezilla-common (3.28.0-1) ...
Selecting previously unselected package libfilezilla0.
Preparing to unpack .../1-libfilezilla0_0.11.0-1_amd64.deb ...
Unpacking libfilezilla0 (0.11.0-1) ...
Selecting previously unselected package libpugixml1v5:amd64.
Preparing to unpack .../2-libpugixml1v5_1.8.1-7_amd64.deb ...
Unpacking libpugixml1v5:amd64 (1.8.1-7) ...
Selecting previously unselected package libwxbase3.0-0v5:amd64.
Preparing to unpack .../3-libwxbase3.0-0v5_3.0.4+dfsg-3_amd64.deb ...
Unpacking libwxbase3.0-0v5:amd64 (3.0.4+dfsg-3) ...
Selecting previously unselected package libwxgtk3.0-0v5:amd64.
Preparing to unpack .../4-libwxgtk3.0-0v5_3.0.4+dfsg-3_amd64.deb ...
Unpacking libwxgtk3.0-0v5:amd64 (3.0.4+dfsg-3) ...
Selecting previously unselected package filezilla.
Preparing to unpack .../5-filezilla_3.28.0-1_amd64.deb ...
Unpacking filezilla (3.28.0-1) ...
Setting up libpugixml1v5:amd64 (1.8.1-7) ...
Setting up libwxbase3.0-0v5:amd64 (3.0.4+dfsg-3) ...
Setting up filezilla-common (3.28.0-1) ...
Setting up libfilezilla0 (0.11.0-1) ...
Setting up libwxgtk3.0-0v5:amd64 (3.0.4+dfsg-3) ...
Setting up filezilla (3.28.0-1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...

Now you are all set, you can see FileZilla in installed application list

How to install packages using snap Ubuntu

Snap is Canonical’s attempt to refine the app packaging and delivery mechanism on the Linux platform.  The Snap packages enable developers to bring much newer versions of apps to Ubuntu 16.04 LTS. Currently, the list of available snap packages is short, but soon we’ll be able to install more packages through the new snap package manager.

It is possible to install snap packages alongside traditional deb packages. These two packaging formats live comfortably next to one another. ( Read more about it here)

If you are on Ubuntu 16.04 LTS or later, you would already have snap installed on your machine, if you are on earlier version, install snap using following command.

$sudo apt install snapd

If you want to cross check if snap is installed or not, run following command.

~$ sudo apt list snapd
[sudo] password for conquistador:
Listing... Done
snapd/xenial-updates,now 2.34.2 amd64 [installed,automatic]
N: There is 1 additional version. Please use the '-a' switch to see it

Check the snap version

$ snap version
snap 2.36.1
snapd 2.36.1
series 16
ubuntu 16.04
kernel 4.15.0-39-generic

Now let us see how to find a package and install it.

Search package by name

$ snap find vscode
Name Version Publisher Notes Summary
vscode 1.29.1-1542309157 snapcrafters classic Code editing. Redefined.
ampareinvertcolor 1.0.0 juthawong - Simply Invert CSS Color - Made For Web Designer

You can search for keywords as well. If keyword has multiple words, please enclose it in single or double inverted commas.

$ snap find "image editor"
Name             Version         Publisher          Notes  Summary
pencilsheep      5               pencilsheep        -      Free professional image editor with full GPU acceleration
amparepngtoico   1.0.1           juthawong          -      Convert PNG Image To Windows Icon File in Clicks
nomacs           3.11.7          diemmarkus         -      nomacs is a free, open source image viewer.
imeditor         0.7             huluti             -      Simple & versatile image editor.
anituner         2.0             mmtrt              -      AniTuner lets you create, edit and convert Windows animated cursors ani files.
gimp             2.10.8          snapcrafters       -      GNU Image Manipulation Program
paintsupreme-3d  1.0.41          braindistrict      -      PaintSupreme 3D
goxel            0+git.5cabc00   guillaume          -      Goxel. Free and Open Source 3D Voxel Editor
carnet           0.9.0           alexandre-roux-m   -      Powerful note taking app with sync, online editor and android app
anifx            1.0             mmtrt              -      AniFX is a free cursor editor with many features.
tiled            1.1.6           bjorn              -      Your free, easy to use and flexible tile map editor.
polarr           5.2.1           polarrco*          -      Powerful and easy-to-use photo editor.
skrifa-lite      0.1.0           hyuchia            -      A simple word processor built with web technologies
skrifa           0.2.6           hyuchia            -      A simple word processor built with web technologies
photoscape       latest          merlijn-sebrechts  -      PhotoScape is a fun and easy photo editing software that enables you to fix and enhance photos.
kstars           master+38b187e  kde*               -      KStars is a desktop planetarium for amateur and professional astronomers.
gitkraken        4.1.1           gitkraken*         -      For repo management, in-app code editing & issue tracking.

Installation.

sudo snap install <package>

For some application you might need to use word –classic.  I got an error which installing visual studio code (vscode) using snap e.g.

$ sudo snap install vscode
[sudo] password for conquistador: 
error: This revision of snap "vscode" was published using classic confinement and thus may perform
arbitrary system changes outside of the security sandbox that snaps are usually confined to,
which may put your system at risk.

If you understand and want to proceed repeat the command including --classic.
$ sudo snap install --classic vscode
vscode 1.29.1-1542309157 from Snapcrafters installed

Snap packages are automatically updated, if you want to update any package manually, use following command.

sudo snap refresh <package>

Check list of packages installed on your computer

$ snap list
Name           Version            Rev   Tracking  Publisher     Notes
core           16-2.36.1          5897  stable    canonical*    core
vscode         1.29.1-1542309157  69    stable    snapcrafters  classic
wine-platform  3.0.3-3.21.0       36    stable    mmtrt         -

Removing the application

sudo snap remove <package>

One the application is installed, it can be run as any other application.

If you want to go into details, please refer to official tutorial and documentation

How to install Visual Studio Code on Ubuntu

Visual studio has been one of the leading code editor. I mostly use sublime text for its simplicity but many a times, Visual studio code feel more comfortable considering many add on features like git integration, debugging tools, autocomplete and not to forget inbuilt terminal.

Method#1 Install Visual Studio Code using .deb package

Step#1 Download Visual Studio code .deb/ *.rem package from https://code.visualstudio.com

Step#2 Install downloaded package using following command

sudo dpkg -i DEB_PACKAGE

Alternatively, you can simply double click on *.deb package. It will open software center page as below. Simply click on install. One you click on install, it will prompt you for password. Install the password and hit enter / click Authenticate.

Method#2 Install Visual Studio code from Ubuntu Software

Got to Ubuntu Software. ( by searching Ubuntu software in search box). Type Visual Studio in the Ubuntu Software sear box and you will see the Visual Studio Code, click on “install” button and you are good to go.

One you click on install, it will prompt you for password. Install the password and hit enter / click Authenticate.

Method#3 Install Visual Studio Code using snap

This is easiest method. Simple run following command and visual studio code will be installed immediately.

$ sudo snap install --classic vscode
vscode 1.29.1-1542309157 from Snapcrafters installed

If you want to know more about what is snap and how to use it ? please read this article

How to remove Visual Studio from Ubuntu

Method#1  Using Ubuntu Software

Got to Ubuntu Software. ( by searching Ubuntu software in search box). Type Visual Studio in the Ubuntu Software sear box and you will see the Visual Studio Code, click on “remove” button and you are good to go.

One you click on remove, it will prompt you for password. Install the password and hit enter / click Authenticate.

Method#2  Using Command Prompt

Just to check if Visual Studio Code is installed, run following command.

$ sudo apt list code
Listing... Done
code/stable,now 1.29.1-1542309157 amd64 [installed]

As you can see, name of the package is code. Now run following command

$ sudo apt-get remove code
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
code
0 upgraded, 0 newly installed, 1 to remove and 197 not upgraded.
After this operation, 193 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 323562 files and directories currently installed.)
Removing code (1.29.1-1542309157) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20180209-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...

Method#3  Using snap

Use this only if you have installed If you have installed Visual Studio code using snap then use following command

$ sudo snap remove  vscode
vscode removed

Note: You can use snap command to uninstall if you have installed using snap or installed from Ubuntu software center, however, if you have installed using .deb file, snap will not be able to remove the package

Upgrading Visual Studio code
Following command will upgrade all packages install on Ubuntu to their latest version

sudo apt update && sudo apt upgrade

How to screen capture to GIF using Byzanz Ubuntu

Byzanz is best way to record GIF on ubuntu, only disadvantage is that its command line tool (to few like me, this is an advantage )

Simplest way to create GIF

byzanz-record --duration=5 out.gif

Now if you want to add delay of few seconds

byzanz-record --delay=5 --duration=10 out.gif

If you want to record specific dementions ?

byzanz-record --duration=15 --x=200 --y=300 --width=700 --height=400 out.gif

Here is sample recording

byzanz GIF