How To Install Django, Flask, InfluxDB, Node, Go, MongoDB on Ubuntu

In this article you can find some installing instructions. Django, Flask, InfluxDB, Node, Go, MongoDB Installation available in this post. These installing instructions for Ubuntu only. Ubuntu is an open source software operating system that runs from the desktop, to the cloud, to all your internet connected things. You can use Ubuntu as a Portable OS.


How To Install Node.js on Ubuntu


Node.js

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. JavaScript is used primarily for client-side scripting, in which scripts written in JavaScript are embedded in a webpage’s HTML and run client-side by a JavaScript engine in the user’s web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser. Consequently, Node.js represents a “JavaScript everywhere” paradigm,unifying web application development around a single programming language, rather than different languages for server side and client side scripts.

Supported Ubuntu versions:

NodeSource will maintain Ubuntu distributions in active support by Canonical, including LTS and the intermediate releases.

  • Ubuntu 14.04 LTS (Trusty Tahr) – not available for Node.js 10 and later
  • Ubuntu 16.04 LTS (Xenial Xerus)
  • Ubuntu 18.04 LTS (Bionic Beaver)
  • Ubuntu 18.10 (Cosmic Cuttlefish)

Installing Node.js via package manager

Installation instructions

Node.js v11.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs

Node.js v10.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs

Node.js v8.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs

To check which version of Node.js you have installed after these initial steps, type:

nodejs -v

Manual installation

If you’re not a fan of curl <url> | bash -, or are using an unsupported distribution, you can try a manual installation.

These instructions assume sudo is present, however some distributions do not include this command by default, particularly those focused on a minimal environment. In this case, you should install sudo or su to root to run the commands directly.

1. Remove the old PPA if it exists

This step is only required if you previously used Chris Lea’s Node.js PPA.

# add-apt-repository may not be present on some Ubuntu releases:
# sudo apt-get install python-software-properties
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save

2. Add the NodeSource package signing key

curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
# wget can also be used:
# wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -

3. Add the desired NodeSource repository

# Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
VERSION=node_8.x
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
DISTRO="$(lsb_release -s -c)"
echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list

4. Update package lists and install Node.js

sudo apt-get update
sudo apt-get install nodejs

How to install MongoDB in ubuntu


What is MongoDB?

MongoDB is a cross-platform document-oriented database program. It is issued under the Server Side Public License (SSPL) version 1, which was submitted for certification to the Open Source Initiative but later withdrawn in lieu of SSPL version 2. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemata. MongoDB is developed by MongoDB Inc.

A NoSQL (originally referring to “non SQL” or “non relational”) database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.

Features

  • MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time
  • The document model maps to the objects in your application code, making data easy to work with
  • Ad hoc queries, indexing, and real time aggregation provide powerful ways to access and analyze your data
  • MongoDB is a distributed database at its core, so high availability, horizontal scaling, and geographic distribution are built in and easy to use
  • MongoDB is free and open-source. Versions released prior to October 16, 2018 are published under the AGPL.

Insatllation

MongoDB Version

This tutorial installs MongoDB 4.0 Community Edition . For other versions of MongoDB, refer to the corresponding version of the manual.

Platform Support

MongoDB only provides packages for the following 64-bit LTS (long-term support) Ubuntu releases:

  • 14.04 LTS (trusty)
  • 16.04 LTS (xenial)
  • 18.04 LTS (bionic)

Step 1 — Adding the MongoDB Repository

MongoDB is already included in Ubuntu package repositories, but the official MongoDB repository provides most up-to-date version and is the recommended way of installing the software. In this step, we will add this official repository to our server.

Ubuntu ensures the authenticity of software packages by verifying that they are signed with GPG keys, so we first have to import they key for the official MongoDB repository.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Next, we have to add the MongoDB repository details so apt will know where to download the packages from.

Issue the following command to create a list file for MongoDB.

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

After adding the repository details, Reload local package database.

sudo apt-get update

Step 2 —Install the MongoDB packages

To install the latest stable version, issue the following

sudo apt-get install -y mongodb-org

This command will install several packages containing latest stable version of MongoDB along with helpful management tools for the MongoDB server.

Next, start MongoDB with systemctl.

sudo systemctl start mongod

You can also use systemctl to check that the service has started properly.

sudo systemctl status mongod

The last step is to enable automatically starting MongoDB when the system starts.

sudo systemctl enable mongod

The MongoDB server is now configured and running, and you can manage the MongoDB service using the systemctl command (e.g. sudo systemctl stop mongod, sudo systemctl start mongod).

Step 3 — Adjusting the Firewall (Optional)

Assuming you have followed the initial server setup tutorial instructions to enable the firewall on your server, MongoDB server will be inaccessible from the internet.

To allow access to MongoDB on its default port 27017 from everywhere, you could use sudo ufw allow 27017.

sudo ufw allow from your_other_server_ip/32 to any port 27017

You can verify the change in firewall settings with ufw.

sudo ufw status

You should see traffic to 27017 port allowed in the output

Output
Status: active

To                         Action      From
--                         ------      ----
27017                      ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
27017 (v6)                 ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)

How to Install InfluxDB on Ubuntu


What is InfluxDB?

InfluxDB is an open-source time series database (TSDB) developed by InfluxData. It is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.

What is a Time Series Database?

A Time Series Database (TSDB) is a database optimized for time-stamped or time series data. Time series data are simply measurements or events that are tracked, monitored, downsampled, and aggregated over time. This could be server metrics, application performance monitoring, network data, sensor data, events, clicks, trades in a market, and many other types of analytics data.

For more information read this article http://iotbyhvm.ooo/what-is-a-time-series-database/

Install InfluxDB

1. First, update all your current system packages by the command

sudo apt-get update

2. Add “InfluxDB” key to verify the packages that will be installed by the below command.

sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add –

3. Add “InfluxDB” to the repository file by the below command.

sudo echo “deb https://repos.influxdata.com/ubuntu trusty stable” | sudo tee /etc/apt/sources.list.d/influxdb.list

4. Re-update your system packages with the command

sudo apt-get update

5. Now you are ready to run the below command to install InfluxDB.

sudo apt-get -y install influxdb

6. Now you had successfully installed InfluxDB, you can open it from the web page by entering your IP address following by “:8083”.

7. To create a super admin with all privileges by the command below on the query box.

CREATE USER “admin” WITH PASSWORD ‘password’ WITH ALL PRIVILEGES

8. Run the query “Show users” to make sure that your admin user is created successfully.

Enable authentication

By default, authentication isn’t enabled on InfluxDB to enable follow the given below steps.

1.Open the configuration file with the nano editor by the below command.

sudo nano /etc/influxdb/influxdb.conf

2. Search for “Auth-Enabled” and change it from “false” to “true” like the screenshot below.

3. Restart InfluxDB so changes take effect by the below command.

sudo service influxdb restart

How to Install Go on Ubuntu


What is Go?

Go is an open source, compiled, concurrent, garbage-collected, statically typed language developed at Google. Google created it to solve its own problems in relation to multicore processors, networked systems and large codebases. While languages such as C and C++ are fast, they are hard to master and development takes longer. While Python is easier to work with, it compromises on runtime efficiency. Go was designed to be efficient, scalable and productive. This programming language designed by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson.

Install Go

  • Use curl or wget to download the current binary for Go from the official download page. As of this writing, the current version is 1.11 Check the download page for updates, and replace 1.11 with the most recent stable version if necessary.
curl -O https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz
  • Extract the tar file:
tar -xvf go1.11.linux-amd64.tar.gz
  • Adjust the permissions and move the go directory to /usr/local:
sudo chown -R root:root ./go
sudo mv go /usr/local

Adjust the Path Variable

Using a text editor, open the ~/.profile file and add the following two lines to the bottom of the file:

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Save the file, and load the commands into the current shell instance:

source ~/.profile

Test the Installation

According to the official documentation, the following steps are the recommended way to test the success of the installation:

In your home directory create a folder named go, this will be your workspace:

mkdir go

Within that directory create /src/hello and within that directory copy and paste the contents of the file below:

mkdir -p go/src/hello && cd go/src/hello
touch hello.go
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

Build the hello.go file:

go build

Run the script:

./hello

hello, world


How To Install Django on Ubuntu


Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design which follows the model-view-template (MVT) architectural pattern.  Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. So today how I tell you How To Install Django on Ubuntu.

It is maintained by the Django Software Foundation (DSF), an independent organization established as a 501(c)(3) non-profit. Django’s primary goal is to ease the creation of complex, database-driven websites. The framework emphasizes reusability and “pluggability” of components, less code, low coupling, rapid development, and the principle of don’t repeat yourself. Python is used throughout, even for settings files and data models. Django also provides an optional administrative create, read, update and delete interface that is generated dynamically through introspection and configured via admin models.

You may like also: ExpressJS – Web framework for Node.js

Some well-known sites that use Django include the Public Broadcasting Service, Instagram, Mozilla, The Washington Times, Disqus, Bitbucket, and Nextdoor. It was used on Pinterest, but later the site moved to a framework built over Flask.

How To Install Django on Ubuntu

There Are some methods for installing Django:

  • Global install from packages: The official Ubuntu repositories contain Django packages that can be installed with the conventional apt package manager. This is simple, but not as flexible as some other methods. Also, the version contained in the repositories may lag behind the official versions available from the project.
  • Install with pip in a virtual environment: You can create a self-contained environment for your projects using tools like venv and virtualenv. A virtual environment allows you to install Django in a project directory without affecting the larger system, along with other per-project customizations and packages. This is typically the most practical and recommended approach to working with Django.
  • Development version install with git: If you wish to install the latest development version instead of the stable release, you can acquire the code from the Git repo. This is necessary to get the latest features/fixes and can be done within your virtual environment. Development versions do not have the same stability guarantees as more stable versions, however.

We will be installing django in an isolated environment but why? simple because we do not want django packages to mess with os python libraries, we will be using pip to install packages and virtualenv to create virtual environments.pip is a package management system used to install and manage software packages written in Python.

Install python3 Pip
sudo apt-get install python3-pip

Install Virtualenv
sudo pip3 install virtualenv

Create new directory for your project
mkdir -p Code/Django/myapp
cd Code/Django/myapp

Create new Virtual Environment we will call it py3,
virtualenv py3

Once you run above command new directory py3 will be created. Now We need to activate our new py3 environment
source py3/bin/activate
your prompt will be changed to (py3) Code/Django/myapp

Now Install Django. Notice we are not running pip3 command, we will just  run pip inside virtualenv
pip install django

Once Django is installed, you can check the version by
django-admin --version
1.9.2

Lets start new project call firstproject
django-admin startproject firstproject
cd firstproject

Lets start new app blog
python manage.py startapp blog

Now we will start the server
python manage.py runserver

Finally done, Whenever you want to leave the virtual environment just run to
deactivate

Dont forget  to run this command Every time you want to work with your Django app
cd Code/Django/myapp
source py3/bin/activate


How to Install Flask on Ubuntu


Flask is a free and open source micro web framework for Python designed to help developers build secure, scalable and maintainable web applications. It based on the Werkzeug, Jinja, MarkupSafe. It was originally created in 2010 and has since powered some of the largest websites on the internet.

Unlike Django, by default Flask doesn’t include ORM, form validation or any other functionalities provided by third party libraries. Flask is built with extensions in mind, which are Python packages that add functionality to a Flask application.

There are different methods to install Flask, depending on your needs. It can be installed system-wide or in a Python virtual environment using pip.

The main purpose of Python virtual environments is to create an isolated environment for different Python projects. In the way multiple different Flask environments on a single computer and install a specific version of a module on a per project basis without worrying that it will affect your other Flask installations. But If you install Flask into the global environment then you can install only one Flask version on your System.

Dependencies

These distributions will be installed automatically when installing Flask.

  • Werkzeug implements WSGI, the standard Python interface between applications and servers.
  • Jinja is a template language that renders the pages your application serves.
  • MarkupSafe comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks.
  • ItsDangerous securely signs data to ensure its integrity. This is used to protect Flask’s session cookie.
  • Click is a framework for writing command line applications. It provides the flask command and allows adding custom management commands.

Ubuntu 18.04 ships with Python 3.6 by default. You can verify that Python 3 is installed on your system by typing:

python3 -V

output

Python 3.6.6

Create a virtual environment is to use the venv module. To install the python3-venv package that provides the venv module by this command:

sudo apt install python3-venv

Now You can create a virtual environment for our Flask application.

Navigate to the directory where you would like to store your Python 3 virtual environments. It can be any location where your user has read and write permissions.

Create a new directory for your Flask application and navigate into it:

mkdir my_flask_appcd my_flask_app

Create your new virtual environment:

python3 -m venv venv

The command above creates a directory called venv, which contains a copy of the Python binary, the Pip package manager, the standard Python library and other supporting files. You can use any name you want for the virtual environment.

Now  you need to activate it by running the activate script:

source venv/bin/activate

Once activated, the virtual environment’s bin directory will be added at the beginning of the $PATH variable. Also your shell’s prompt will change and it will show the name of the virtual environment you’re currently using. In our case that is venv:

Step 3. Install Flask

Now that the virtual environment is activated, you can use the Python package manager pip to install Flask:

pip install Flask

Within virtual environment, you can use the command pip instead of pip3 and python instead of python3.

Verify the installation

python -m Flask --version

How To use Flask

We will create a simple hello world application which will just display the text “Hello World!”.

Open your text editor or PyCharm and create the following file:

~/my_flask_app/hello.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

Save the file as hello.py

We’ll use the flask command to run the application but before that we need to tell Flask how to load the application by specifying the FLASK_APP environment variable:

export FLASK_APP=helloflask run

The command above will launch the development builtin server.

Output

 * Serving Flask app "hello"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

If you use Flask with virtual machine and you want to access Flask development server then you cnn make the server publicly available by appending --host=0.0.0.0 to the flask run command.

Open http://127.0.0.1:5000 in your web browser and you will be presented with the “Hello World!” message.

To stop the development server type CTRL-C in your terminal.

After finishing your work, deactivate the environment.

deactivate

Visit the Flask documentation page and learn how to develop your first Flask app.


I hope you like this post “How To Install Django, Flask, InfluxDB, Node, Go, MongoDB on Ubuntu” . Do you have any questions? Leave a comment down below! Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

You may like also:


Upvote on Reddit

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning! Follow and send tweets me on @harshvardhanrvm

One thought on “How To Install Django, Flask, InfluxDB, Node, Go, MongoDB on Ubuntu

Leave a Reply

%d bloggers like this: