Friday, December 30, 2016

How To Get Rid Of "N: Ignoring file '20auto-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension" Warning Message In Ubuntu 16.04

How To Get Rid Of
"N: Ignoring file '20auto-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension"
Warning Message In Ubuntu 16.04

shivaraj@shivaraj-A14RM0E:~$ sudo apt upgrade [sudo] password for shivaraj: Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. N: Ignoring file '20auto-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension shivaraj@shivaraj-A14RM0E:~$

As usual, today morning, I ran sudo apt-get -y upgrade in my Ubuntu Linux box.. But at the end of the upgrade I got "N: Ignoring file '20auto-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension".... I googled about it to find the reason for this kind of nasty warnings...

Finally, found the reason and solution for this issue from Ask Ubuntu...

According to AskUbuntu, The reason for this warning message is, the update contains a new version of configuration file.. but if you choose system package manager to keep old one itself... then the new config file would just exists there, along with old configuration file...

So every time we use package manager, it is printing file with invalid extension warning message... However, it will not cause any issues.. We can just ignore it... But if you want to get rid of this warning message.. Just follow the bellow instructions...

We can get rid of this message by removing redundant new configuration file which came with updates..
Just execute bellow command to remove the new redundant configuration file.. So that we can get rid of warning message..

sudo rm -f /etc/apt/apt.conf.d/20auto-upgrades.ucf-dist

Now run sudo apt upgrade... This time you wouldn't get warning message..

shivaraj@shivaraj-A14RM0E:~$ sudo rm -f /etc/apt/apt.conf.d/20auto-upgrades.ucf-dist shivaraj@shivaraj-A14RM0E:~$ sudo apt upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. shivaraj@shivaraj-A14RM0E:~$

Thats all... Follow us on facebook fb.com/opensourceinside..


Sunday, December 25, 2016

How To Send Email From Nodejs To Gmail

How To Send Email From Nodejs To Gmail
(Using NodeMailer)



In PHP, we can send e-mail using mail() function which internally uses/requires sendmail program (or equivalent program like postfix on Linux..)
See how to install and configure postfix to send e-mail from postfix

In the case of NodeJs, we can use NodeMailer NPM module to send emails from NodeJS. Here I'm going to show you how to send email from NodeJs to Gmail using NodeMailer NPM.

Step 1: Create/Initialize New Node Project

Create a folder and run npm init then create file named mail.js

Create New Folder For Node Project and Enter Into That Folder:

mkdir node-email && cd node-email

Now initialize project with npm init

npm init

The output of above command will look like following one..

shivaraj@shivaraj-A14RM0E:~/node-email$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (node-email) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /home/shivaraj/node-email/package.json:

{
  "name": "node-email",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) 
shivaraj@shivaraj-A14RM0E:~/node-email$ 

After completing above step you will see new file named package.json inside your node project directory. with following content..

{ "name": "node-email", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }

Step 2: Now Install NodeMailer NPM

Now install NodeMailer NPM by running following command...

npm install nodemailer --save

You will see output similar to bellow one..

shivaraj@shivaraj-A14RM0E:~/node-email$ npm install nodemailer --save
node-email@1.0.0 /home/shivaraj/node-email
`-- nodemailer@2.7.0 
  +-- libmime@3.0.0 
  | +-- iconv-lite@0.4.15 
  | +-- libbase64@0.1.0 
  | `-- libqp@1.1.0 
  +-- mailcomposer@4.0.0 
  | `-- buildmail@4.0.0 
  |   +-- addressparser@1.0.1 
  |   `-- punycode@2.0.1 
  +-- nodemailer-direct-transport@3.3.2 
  | `-- smtp-connection@2.12.0 
  |   `-- httpntlm@1.6.1 
  |     +-- httpreq@0.4.22 
  |     `-- underscore@1.7.0 
  +-- nodemailer-shared@1.1.0 
  | `-- nodemailer-fetch@1.6.0 
  +-- nodemailer-smtp-pool@2.8.2 
  | `-- nodemailer-wellknown@0.1.10 
  +-- nodemailer-smtp-transport@2.7.2 
  `-- socks@1.1.9 
    +-- ip@1.1.4 
    `-- smart-buffer@1.0.11 

npm WARN node-email@1.0.0 No description
npm WARN node-email@1.0.0 No repository field.
shivaraj@shivaraj-A14RM0E:~/node-email$ 

The package.json file will now look like this...

{ "name": "node-email", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "nodemailer": "^2.7.0" } }

Note the extra line added in package.json file...

"dependencies": { "nodemailer": "^2.7.0" }

The dependencies section indicates installed npm module name and version of that npm module... So we are using NodeMailer version 2.7 for this tutorial...

Step 3: Create app.js

Now create app.js file inside our project folder which is going to host our code for sending email...

Step 4: Now start to write code to send email from nodejs..

Import NodeMailer module into your app.js file...

var nodemailer = require('nodemailer');

Now configure/initialize nodemailer by providing required data...

var transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', port: 465, secure: true, //true --> will use ssl auth: { user: 'yourusername@gmail.com', pass: 'your password' } });
Don't forget to replace user and pass fields with your email ID and password...
You have to Turn On Allow less secure apps in-order to use your nodemailer client work properly with gmail.. To do this go to https://myaccount.google.com/security/lesssecureapps find Allow less secure apps option and Turn On it..



Now send mail with transporter.sendMail(mailOptions, callback)... where mailOptions is an object which holds from address, to address and subject of mail etc... the second one is a callback function...

var mailOptions = { from: 'yourusername@gmail.com', to: 'friend1@gmail.com, friend2@gmail.com', subject: 'Hello', text: 'Hello world', html: '<b>Hello world </b>' }; transporter.sendMail(mailOptions, function(error, info) { if (error) { console.log(error); } else { console.log('Message sent: ' + info.response); } transporter.close(); });

call transport.close() method to close the connection..

The final version of app.js file will look like below one..

var nodemailer = require('nodemailer'); var transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', port: 465, secure: true, auth: { user: 'yourusername@gmail.com', pass: 'your password' } }); var mailOptions = { from: 'yourusername@gmail.com', to: 'friend1@gmail.com, friend2@gmail.com', subject: 'Hello', text: 'Hello world', html: '<b>Hello world </b>' }; transporter.sendMail(mailOptions, function(error, info) { if (error) { console.log(error); } else { console.log('Message sent: ' + info.response); } transporter.close(); });
You can download full code sample from github..

That's all... Now run the app.js file to send email to your friend1@gmail.com, friend2@gmail.com....

node app.js

If your email get delivered successfully then you will see output similar to one shown below..

shivaraj@shivaraj-A14RM0E:~/node-email$ node app.js
Message sent: 250 2.0.0 OK 148xxxxxxx s5sxxxxxxxxxpgj.19 - gsmtp
shivaraj@shivaraj-A14RM0E:~/node-email$ 
Hi friends, If you found any issue or typo error, please feel free to report it.. You can either open an issue on github or you can also report it on our Facebook Page via message (www.fb.com/opensourceinside) .

That's it for now.. If you like don't forget to share it guys.. You can follow us on fb.com/opensourceinside and also subscribe our channel on Youtube..

Happy Coding !!


Thursday, December 15, 2016

How To Install Linux Kernel 4.9 In Ubuntu Linux And Its Derivatives

How To Install Linux Kernel 4.9 In Ubuntu Linux And Its Derivatives


As usual, Last Sunday (11, DEC 2016), Linux creator Linus Torvalds officially announced the final release of Linux Kernel 4.9, codenamed 'Roaring Lionus'. Which is also the final and biggest ever release of 2016. As of writing this, Linux 4.9 is mainline kernel and the most advanced Linux kernel available in market for GNU Linux Distros...
As Soon as it was released, immediately it will be available for rolling release distros such as Arch Linux, Solus, or even openSUSE. Soon it will be available for Fedora users also.. But for Ubuntu, you have to manually install Linux 4.9, if you want to upgrade your current Linux kernel installed in your system. Here we are going to see how to install Linux 4.9 in Ubuntu Linux and It's derivatives.

So new kernel release means, new features, support for more hardware and many more bug fixes and improvements.. Here is some new features and improvements Linux kernel 4.9 brings..

Some Of The New Features Of Linux 4.9

  • Experimental support for older AMD Radeon graphics cards
  • Memory Protection Keys (MPK) are now mainlined.
  • AMDGPU virtual display support.
  • Support for 29 more ARM machines by the mainline Linux kernel.
  • and Click To See More Changes Of Linux 4.9 Here...

Install Linux 4.9

If you want to automate the installation processor.. follow the instructions given Method 1, otherwise if you want to know and install step by step follow Method 2.

Method 1 :

Just open and copy-paste the following in your terminal..

To Install Linux Kernel 4.9 in your system run the following command..

wget -O - https://gist.githubusercontent.com/shivarajnaidu/cfd4ddc12de1798a82d1dbe0b8fad0b2/raw/df86e39b818c9a6e007b0b8bd9736ea1ba0f7800/install_linux4.9_in_ubuntu.sh | sh -s

If script execution completes successfully then you are ready to go.. Just restart your system to use latest kernel... Enjoy !

If you want to remove Linux kernel for any reason.. Just pass 'd' (with out single quotes) as argument to above command

To Remove Linux Kernel 4.9 from your system run the following command..

wget -O - https://gist.githubusercontent.com/shivarajnaidu/cfd4ddc12de1798a82d1dbe0b8fad0b2/raw/df86e39b818c9a6e007b0b8bd9736ea1ba0f7800/install_linux4.9_in_ubuntu.sh | sh -s d

Method 2 :

In this method i will show you step by step process of installing Linux kernel 4.9 .....

First update your system package source list and upgrade all installed packages to latest version by running following commands..

sudo apt-get update; sudo apt-get upgrade
Warning : The Linux kernel is a critical element of the system. To do the upgrade costs when one of your hardware devices is not working properly, and the new kernel may fix this problem. But at the same time installing a new kernel unnecessarily can lead to undesirable regressions, such as: no network connection, no sound or even the inability to boot the system, so install a new kernel on your own risk.

Now make a new folder/directory to download and store required binaries files...

mkdir linux4.9 && cd linux4.9

Now download required files with following command..

For 64 bit:

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900_4.9.0-040900.201612111631_all.deb; wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb; wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb;

For 32 bit:

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900_4.9.0-040900.201612111631_all.deb; wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900-generic_4.9.0-040900.201612111631_i386.deb; wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_i386.deb

Or if you want to download manually.. you can download from here.. and put them in one directory.
if you are downloading manually.. download correct binaries for your architecture...
If you are not sure about your OS architecture.. Run getconf LONG_BIT command.. This will tell you whether the kernel is 64 bit or 32 bit..
See More On Finding System Architecture..

That's all for now.. Don't Like us on fb.com/opensourceinside


Sunday, October 30, 2016

Installing Rust On Ubuntu 16.04 and 14.04

Installing Rust On Ubuntu 16.04 and 14.04


Rust Programming Logo

Rust, also known as Rust-Lang, is a new programming language which aims safety, speed and concurrency... It's designed to create highly concurrent and secure Applications/Systems by having more a number of compile-time safety checks that produce no runtime overhead, while eliminating all data races.... According to documentation, Rust also aims to achieve ‘zero-cost abstractions’ even though some of these abstractions feel like those of a high-level language.

Here.. We are going to see how to install and getting start with rust on Ubuntu Linux 16.04 & 14.04

Step 1: Update Source(Package) List

Open terminal and run the following commands to ensure that package source list is upto date and also install curl...

For Ubuntu 16.04

sudo apt update && sudo apt -y install curl

For Ubuntu 14.04

sudo apt-get update && sudo apt-get -y install curl

Step 2: Install Rust

Now run the following command which download and runs a script that will install rust on your Linux box..

wget -O - https://static.rust-lang.org/rustup.sh | sh

Or If you have curl installed..

curl -sSf https://static.rust-lang.org/rustup.sh | sh

Rust packages are available in three different release channels namely stable, beta and nightly... The above command will install current stable version of rust on your system..

If you want to install beta version(A preview of the upcoming stable release, intended for testing) of rust, run the following command..

wget -O - https://static.rust-lang.org/rustup.sh | sh -s -- --channel=beta

Or

curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=beta

If you want to enjoy features that are not available in stable and beta channels, install rust from nightly release channel.. (Be aware, Features which are available in nightly channel are unstable may change anytime before they get into beta channel)

wget -O - https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly

Or

curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly

Step 3: Verify The Installation

You can verify the successful installation of rust in your System by running rustc -V . You will get output similar to output shown below..

shivaraj@shivaraj-A14RM0E:~$ rustc -V rustc 1.12.1 (d4f39402a 2016-10-19)

Get start with rust..

If you see output similar to above.. that means your installation was successful.. So now here i am going to show how to write a hello world program in rust and run it..

Create file named main.rs, open it with your favorite text-editor, then copy and paste the following code in that file and save it...

fn main() { println!("Hello, World"); }

Now compile it with rustc main.rs, you will get executable file named main .... execute it by running ./main .. You will see.. "Hello, World" text on your screen..

shivaraj@shivaraj-A14RM0E:~$ ./main Hello, World shivaraj@shivaraj-A14RM0E:~$

Here, You Can Learn Rust Programming..


Here is the video for above tutorial...



Happy Coding !!

Wednesday, September 28, 2016

How To Install And Configure Postfix To Send Mail By Using Gmail As Mail Relay In Ubuntu 16.04 & 14.04

How To Install And Configure Postfix To Send Mail By Using Gmail As Mail Relay In Ubuntu 16.04 & 14.04

Postfix is a cross platform, free and opensource Mail Transfer Agent (MTA) designed to be an alternative to the widely-used Sendmail program. The main aim of Postfix is to be fast, easy to administer, and secure. The outside has a definite Sendmail-ish flavor, but the inside is completely different. Today we are going to see how to install and configure Postfix to send E-mail using gmail as mail relay server... and I'm using Ubuntu 16.04 LTS for this tutorial..(also tested in 14..04)

Installation

You can get Postfix from offical Ubuntu repositories.. So you can install it by running the apt install command..

For Ubuntu 16.04

sudo apt update && sudo apt -y install libsasl2-modules postfix

For Ubuntu 14.04

sudo apt-get update && sudo apt-get -y install libsasl2-modules postfix

Postfix Configuration..

During the installation of Postfix, you will be asked to choose default configuration for postfix...
Select Internet Site...


Enter Fully Qualified Domain Name(FQDN).. for example if you are going to use myuser.example.com then you have to fill example.com for following field..


After installation has completed successfully, proceed following steps to use gmail SMTP server as relayhost.

Configuring Postfix To Use Gmail's SMTP server as Relayhost..

Now we will see how to configure Postfix to send E-mails using gmail as relay host.. To do this we need to edit /etc/postfix/main.cf... open main.cf file in your favorite text editor.. here i am using sublime text(it's my favorite editor )..
See How To Install Sublime Text On Linux

subl /etc/postfix/main.cf

If you want to open with gedit run following the command..

sudo gedit /etc/postfix/main.cf

Then add following lines to the end of main.cf file..

# enable SASL authentication smtp_sasl_auth_enable = yes # disallow methods that allow anonymous authentication. smtp_sasl_security_options = noanonymous # where to find sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # Enable STARTTLS encryption smtp_use_tls = yes # where to find CA certificates smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

And also set relayhost value to [smtp.gmail.com]:587..

relayhost = [smtp.gmail.com]:587

Configure Gmail Username and Password For Authentication :

first you have to create file named sasl_passwd inside /etc/postfix/...

sudo touch /etc/postfix/sasl_passwd

Then open recently created file with your choice of text editor..

sudo gedit /etc/postfix/sasl_passwd

or, if you have sublime text editor... run following..

subl /etc/postfix/sasl_passwd

Now add your smtp server address, port, username and password details in the format shown below..

[smtp relayhost ip or name]:port username:password

For our case (gmail)... following is more suitable example...

[smtp.gmail.com]:587 abcd@gmail.com:mypassword
You have to Turn On Allow less secure apps in-order to use your Postfix MTA work properly with gmail.. To do this go to https://myaccount.google.com/security/lesssecureapps find Allow less secure apps option and Turn On it..



Don't forget to replace with abcd and mypassword with your username and password..

then save and create lookup-table or hash for above file.. by running postmap command..
if you ma any changes

sudo postmap /etc/postfix/sasl_passwd
The above command will create new file sasl_passwd.db in the same location as sasl_passwd file exists..
You should recompile sasl_passwd file.. means you have to run above command whenever you make change in sasl_passwd file...

Restart or Reload Postfix :

Before you use, You should reload or restart Postfix whenever you make changes to main.cf file..

For Ubuntu 16.04

sudo systemctl restart postfix

For Ubuntu 14.04

sudo service postfix restart

Or you can reload postfix with it's own implementation..

sudo postfix reload

Testing Postfix Installation

The easy way to test your postfix installation and configuration is use mail command or sendmail command..

Testing using mail command :

You can use mail command to send mail as follows..

echo message_text | mail -s "subject" Recipient Email Address

For example.. if you want to send mail to myfriendd@outlook.com ... the above command will looks like the following one..

echo Hello | mail -s "Test Mail Subject" shivarajnaidu@outlook.com

Testing using sendmail command :

You can even postfix's implementation of sendmail command..

sendmail shivarajnaidu@outlook.com From: you@example.com Subject: Test Mail Subject Hello .
Note the trailing "." (dot) in sendmail command example.
Usually send mail will consider "." (dot) as end of message

Debugging :

If you didn't receive mail, when you test with above commands.. then see mail.log and mail.err files which are present in /var/log/... From these two files you can point-out the problem and it will be helpful for troubleshooting the problem.


Here is the video for above tutorial...


That's it for now.. If you like don't forget to share it guys.. You can follow us on fb.com/opensourceinside and also subscribe our channel on Youtube..


Thursday, September 22, 2016

Create Password Protected PDF Files Using LibreOffice

Create Password Protected PDF Files Using LibreOffice

Portable Document Format (PDF) is one of the commonly used file formats in our day to day life.. There may be a times, we need to create PDF files from word documents.. Here I am going to show you how to create PDF files from word documents and protect them with passwords (using Libre Office)

Step 1 :

Open your document with LibreOffice which you want to convert into PDF format...

Step 2 :

Then goto File menu and select Export As PDF

Now you will see dialog box like one shown below..

Step 3 :

Then Navigate to tab named Security and Click Set Passwords button..

After Clicked on Set Passwords button you will see set password dialog shown below..
Enter the password you want to set to PDF file.. and click on OK.. and then on Export

Step 4 :

When you click on Export you will get save dialog box like one shown below..
You can save your newely created PDF document on your file system..

Step 5 :

Now try to open newely created PDF document ... It will ask you for password to open the PDF document...

That's it for now ... You can follow us on fb.com/opensourceinside and take a glipse of our youtube channel and don't forget to Subscribe it guys..


Here is the video for above tip...



Tuesday, September 20, 2016

How To Remove Password From Password Protected PDF File Using Google Chrome

How To Remove Password From Password Protected PDF File Using Google Chrome

Portable Document Format (PDF) is one of the commonly used file formats in our day to day life... While it offers grade of security with optional password protection, there are times when we may need unsecured copy of password protected PDF file.
Here, we are going to see, how to achieve the above with the evergreen web browser Google Chrome (of course, we can do the same with Mozilla Firefox )

So, Before we start, you need to have Google Chrome installed in your system... (See, How To Install Google Chrome On Ubuntu Linux).

Step 1 :

Open your password protected PDF file either with Google Chrome or with Mozilla Firefox...

Step 2 :

It will ask you for password ... provide it..
After entering password the PDF will be displayed by your browser..

Step 3 :

Now, Press Ctrl + P on your keyboard or go to options and click on Print option..

After you click on print option you will see dialog like shown below..

Step 4 :

Now click on Save button and Save the new copy of PDF file in somewhere else..
This new copy is password free ....


That's it ... Your new password less copy of PDF file is now ready...

Friends.. If you like this tip.. Do share this small trick on social media with your friends... You can follow more updates on our Facebook page


Here is the video for above tip...



Friday, September 16, 2016

Installing phpMyAdmin in Ubuntu 16.04

Installing phpMyAdmin in Ubuntu 16.04


phpMyAdmin is an open source tool used for the administration/management of MySQL or MariaDB with the use of a web browser. In addition to offering the capability to perform administration tasks such as creating, editing, or deleting databases, and managing users and permissions, phpMyAdmin provides a graphical user interface to do all of these tasks and more. Here, we are going to see how to install, up and run phpMyAdmin on Ubuntu 16.04.

Install phpMyAdmin

Before you start installing phpmyadmin, install PHP, apache and MySql or similar Db..

Then.. Run following command .. to install phpMyadmin on your Ubuntu installation...

sudo apt -y update && sudo apt install phpmyadmin

Continue with typing Y once the installation prompts you with Do you want to continue [Y/n]? Like in the image below.


Now we are prompted with dialog selecting our web server, in our case we are selecting apache2 like shown below.


Select <Yes> as we just want a basic installation like shown below.


Now provide a password for phpMyAdmin to use. So that it can register with the MySQL database itself. (Need not to be the same as the MySQL root user)


Enter in the phpMyAdmin password you created in last step to confirm it as follows.


phpMyAdmin is now installed, but, still we have a few more things to do.

Testing phpMyAdmin

Now we will test phpMyAdmin! Open your favorite Web Browser..
and Navigate to http://localhost/phpmyadmin/

If you end up with a page that looks like one shown below... means, phpMyadmin was installed successfully on your system..


Now lets login, the default username for phpMyAdmin is root and the password is what you have entered while installing phpMyadmin... Enter as follows.

Username: root

Password: What you selected earlier

Select Go to login.

When you log in, you'll see the user interface, which will look something like this:


Hi friends, If you found any issue or typo error, please feel free to report it.. You can report it on our Facebook Page via message (www.fb.com/opensourceinside) .

Wednesday, August 31, 2016

Installing ElasticSearch On ubuntu 16.04 and 14.04

Installing ElasticSearch On ubuntu 16.04 and 14.04



Updated On DEC 2016: Installation Script In Method 2 updated for installation of elastic search 5.x

Elasticsearch is a highly scalable open-source full-text search and analytics engine build on top of Apache Lucene(A free and open-source information retrieval software library). It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.

Here we are going to see, How to install and setup elasticsearch on Ubuntu Linux 16.04 and 14.04..
Here I am going to show you two ways to install elasticsearch on Ubuntu Linux..

The first one is manual installation of elasticsearch.. You have to follow instructions one by one ..
The second one is an easy way, there we use shell-script to install the elasticsearch as it would take care of all things.. The script will install and setup elasticsearch for you..

Installation :

Method 1 :

First things first, Before we start to install elasticsearch, we need to install Java Runtime Environment (JRE).. because Elasticsearch itself written in the Java. (Elasticsearch requires Java 7 or higher).
This step shows you how to install OpenJDK-8.
First, update the list of available packages by running apt-get update.

sudo apt-get update

Then, install OpenJDK with the command:

For Ubuntu 16.04 :

sudo apt-get -y install openjdk-8-jdk openjdk-8-jre

For Ubuntu 14.04 :

sudo add-apt-repository -y ppa:openjdk-r/ppa && sudo apt-get update && sudo apt-get -y install openjdk-8-jdk openjdk-8-jre

To verify your JRE is installed and can be used, run the command: java -version

The result should look like this:

openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
If You Have Already Installed Version of JAVA in Your System.. Please Set OpenJDK 8 as Default Version.. Otherwise you may encounter problems while starting elasticsearch.. You can configure multiple versions of java by running following command.. sudo update-alternatives --config java Now, select apropriate version of JAVA..
to verify the java version run.. java -version

Download and Install Elasticsearch :

Elasticsearch can be downloaded directly from official site as zip, tar.gz and deb

I will recommend.. Installing from zip or tar archive.. Because as far as I knew it is the best way to get Elasticsearch on Ubuntu ... from my experience the another way (installing from .deb) is very worst... has many nasty issues(tried on Ubuntu 16.04)..

Download the archive

cd && wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.3.5/elasticsearch-2.3.5.zip

The above command downloads the zip archive, make sure that you have unzip installed in your system... if don't have installed unzip in your system.. run the following command.. to install unzip

sudo apt-get install unzip

Now unzip/decompress the downloaded archive.. you can do this with command given below..

unzip elasticsearch-2.3.5.zip

Move Extracted/unzipped directory to /opt :

We don't want to pollute our home folder and make it ugly with too many folders apart from default one.. and moving elasticsearch to /opt directory will also make it available to other users in your system too..

If you already have directory named elasticsearch-* in your /opt directory you will/may encounter problems while trying to move our newly extracted folder into /opt . so better remove them before you move our new elasticsearch folder into /opt. to do this run following command.... sudo rm -r /opt/elasticsearch-2*

Now move newly extracted elasticsearch directory to /opt with following command..

sudo mv elasticsearch-2.3.5/ /opt/

Now your elasticsearch is ready to use, You can run it with following command..

/opt/elasticsearch-2.3.5/bin/elasticsearch

But it's so convenient, if we can able to start it from commandline.. by simply typing 'elasticsearch' .. just like normal system commands.. to do so.. we have to create a symbolic link for elasticsearch in /bin folder.. Run following commands....

First remove symbolic link if one already exists..

sudo rm /bin/elasticsearch

now.. create new symbolic link ...

sudo ln -s /opt/elasticsearch-2.3.5/bin/elasticsearch /bin/

That's it .. now you can start elasticsearch just by typing "elasticsearch" in your terminal window..

Now the other method (method 2) show you the easiest way of getting elasticsearch up and running on your Ubuntu installation..

Method 2 :

In this method ... You just need to run the following code ... the script will take care of remaining things..

wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s

Update :

The installation script is updated to support installation of elasticsearch v5.x. If you want to install elasticsearch 5.x, just run above command with argument '5' (with out quotes).

wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s 5

Test your Elasticsearch installation

Start elasticsearch by typing "elasticsearch" on your command-line..
Let's ensure that everything is working well... open terminal and Run following..

elasticsearch
Elasticsearch should now be running on port 9200. Do note that Elasticsearch takes some time to fully start, so running the curl command below or checking from browser immediately might fail. It shouldn't take longer than ten seconds to start responding, so if the below command fails, something else is likely wrong. Ensure the server is started by running

To test elasticsearch run following command in terminal..

curl -X GET 'http://localhost:9200'

or even you can check from your web browser by visiting http://localhost:9200

if elasticsearch works well.. You should see the following response..

shivaraj@shivaraj-A14RM0E:~$ curl -X GET 'http://localhost:9200' { "name" : "Suicide", "cluster_name" : "elasticsearch", "version" : { "number" : "2.3.5", "build_hash" : "90f439ff60a3c0f497f91663701e64ccd01edbb4", "build_timestamp" : "2016-07-27T10:36:52Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" } shivaraj@shivaraj-A14RM0E:~$
Hi friends, If you found any issue or typo error, please feel free to report it.. You can either open an issue on github or you can also report it on our Facebook Page via message (www.fb.com/opensourceinside) .