Add Environment variables in Linux permanently

There are two ways to setup environment variables in linux systems ( Ubuntu , Red Hat , Fedora etc)

  • Using the export method of adding environment variables to linux . However it is only temporary solution , it will make variables available only for current session.
  • Editing .bash_profile file and adding it there permanently

Using export

Consider the example you want to add JAVA_HOME variable for java installation at /usr/java/

Using export we would type command like

# export JAVA_HOME=/usr/java

To add it to our PATH variable we would type

# export PATH=$PATH:$JAVA_HOME/bin

The above command says add the bin directory in JAVA_HOME to the PATH variable

However using export would not be permanent and would be gone when your session is over

Using bash_profile

Assuming that you are using default bash shell (  See note in end )

 

To add environment variable permanently we have to edit the bash_profile file.

Move to your home directory (e.g /home/yourname and type )

# vi .bash_profile

The above command may ask for root user rights , so in that case you have to type like

# sudo vi .bash_profile

The full stop (.) before the file name makes it a hidden file

Type in the end of the file any path variable you want to add

e.g

JAVA_HOME=/usr/java/jdk1.6.0_26

export JAVA_HOME

PATH=$PATH:$JAVA_HOME/bin

export PATH

type i to enter the insert mode

then add whatever you want to the end of it. Press the escape key to exit the INSERT mode.

Type :w to write the file

Type q to quit the vi editor

That’s it. The path variable has been stored permanently in the Linux system

--------------------------

NOTE:

Depending upon the shell you are using , you need to edit .profile or .bash_profile file.

To find out type echo $SHELL

If you are using ksh,
Edit ~/.profile to add any evn. variable.
e.g.
MY_LIBS=/home/my/libs
export MY_LIBS.

If you are using bash,
Edit ~/.bash_profile to add the env.
To find out what shell you are usin, do
echo $SHELL or
cat /etc/passwd | grep `id -un`

Tomcat directories explained

Here is brief summary of functions of various directories in tomcat
bin  : The bin directory contains the shell scripts and batch files for starting . We use mainly startup.sh to start the catalina. Internally it gives call to catalina.sh file to execute. The envorionment variables of JAVA_HOME , CATALINA_HOME are mandatory for tomcat catalina.sh to work.

conf : The conf directory contains the configuration files for Tomcat. These include general server configuration files, a default user list for file-based authentication and security for Web applications, and a global configuration

logs : The <TOMCAT_HOME>/logs directory contains the server logs.

lib : The <TOMCAT_HOME>/lib directory contains all the JAR files used by Tomcat.

webapps : This directory contains all the Web applications provided with Tomcat by default.
work : The work directory contains temporary files, precompiled JSP pages, and other intermediate files.

webapps : This is the place where we will place our war files . Tomcat automatically explodes them into directories. Tomcat also has applications of manager and host-manager which allows us to manage applications and hosts respectively.

How to install Tomcat in Linux (Ubuntu)

To install Tomcat we need Java to be installed in the system. If you want to know how to install Java on Linux you can refer this earlier post on the same.

We can install Java either using packages (apt , yum) or manually. This post explains how to do it manually.

The main advantage of doing it manually is that all the tomcat files are in one location. The automated installation will spread the setup files across various locations. It places the Tomcat configuration files at various non standard places.

Steps

1) Login to shell and go to folder where you want to install tomcat . In this example i am doing it in folder in /usr . The shell commands are shown by # statements , it can be $ for you. It doesn’t matter. If the user with which you are logged in is not root. Then you need to prefix commands with sudo.

# cd /usr

# sudo mkdir tomcat7

# cd tomcat7

Download the zip of tomcat files from tomcat website

# sudo wget http://mirror.metrocast.net/apache/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip

This will download the tomcat zip into tomcat7 directory , next you need to unzip it

# unzip apache-tomcat-7.0.16.zip

This will create a folder named apache-tomcat-7.0.16 in the tomcat 7 folder. The apache-tomcat-7.0.16 is your tomcat home ( CATALINA_HOME environment variable)

Setting up of tomcat environment and path variables

Both JAVA_HOME and CATALINA_HOME environment variables and its path is required for tomcat to run.

# export CATALINA_HOME=/usr/tomcat7/apache-tomcat-7.0.16

# export PATH=$PATH:$CATALINA_HOME/bin

Now its time to start the tomcat. But before this we need to give execute permissions to bin directory files of tomcat

# cd apache-tomcat-7.0.16/bin

# sudo chmod 775 *

If you run tomcat without giving execute permissions you will get error like

The BASEDIR environment variable is not defined correctly.

Time to start tomcat

# sudo sh startup.sh

You can test it by opening

http://localhost:8080 in the browser

Hope it was useful , please don’t forget to write your comments and suggestions

How to install Java and JDK in Linux (Ubuntu)

We can install Java either using packages or manually. This post explains how to do it manually.

If you want jdk to be available only for particular user , then do it in his home directory. Otherwise if you want to make it available for all the users its better to do it in /usr directory.

Steps

1) Login to shell and go to folder where you want to install jdk . In this example i am doing it in folder in /usr . The shell commands are shown by # statements , it can be $ for you. It doesn’t matter. If the user with which you are logged in is not root. Then you need to prefix commands with sudo.

# cd /usr

# sudo mkdir java

# cd java

Download the latest version of jdk from oracle website. You can also isntall Open jdk . The steps would be more of less same. Just change would be file name and from where to get it.

Go to Oracle website and open the Java downloads page. Click JDK and you will be presented with various files which you can download depending upon your platform. If your machine is 32 bit you would download x86 setup . If its 64 bit then you will download x64 setup.

My machine is 32 bit so i am downloading setup accordingly.

# sudo wget http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-i586.bin

The above command will downlad the jdk binary to java directory.

Next step is to change the permissions for the file to execute and start the install process

# chmod o+x jdk-6u26-linux-i586.bin

# ./ jdk-6u26-linux-i586.bin

This will complete the install process and will create one folder named jdk1.6.0_26 in the java directory. This is your java home and you are done.

Setting up Java environment and path variables.

To setup the environment variables

# export JAVA_HOME=/usr/java/jdk1.6.0_26

Setting the Java path use the following command

# export PATH = $PATH:$JAVA_HOME/bin

This will setup your JAVA_HOME , we can test our java installation with following command

# java –version

It will show the Java version installed.

Validating Web.xml file

While working with java web application development often we need to install applications again and again on web server / application server. And often when we deploy application after modification to web.xml application fails to get deployed giving long error in Tomcat ( or any other server) console.

To check validation of web.xml before deploying we can validate it with standard web.xml dtd

I used ant to handle deployment / stopping / starting application in tomcat.

You can use the following ant task to check validation of web.xml

 

<target name="checkwebxml" description="Validate the web xml">

<xmlvalidate failonerror="yes" lenient="yes" warn="yes" file="./web/WEB-INF/web.xml">

<dtd publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

location="web-app_3_0.dtd"/>

</xmlvalidate>

</target>

 

You can make compilation target dependent on checkwebxml task so that compilation and deployment doesn't starts before validation of web.xml

This will ease our task to find error in tomcat console when we try to deploy our application

UPSC Civil services 2011 Preliminary Exam Paper 2 Answers

UPSC 2011 Civil Services Preliminary Exam Analysis

Just came after giving exam for UPSC Civils 2011

Here are my personal thoughts ( PS : I am not any expert , there are just my own views)

Paper 1

Total questions were 100 , time was 2 hours

Gone are those days when exams were full of Indian history , i feel UPSC has moved on and now they are testing us for current events. People who read papers like The Hindu and Frontline magazine should feel they are on right track to prepare for exam like this. Paper was logical and nothing like what happened in year xxxx bla bla types questions.

Current affairs , geography , economics topics of inflation and banking were tested often.

Paper 2

Total questions were 80 , time was 2 hours

It was exam with lots of English questions . Frankly i was astonished to see so many English passages. I don’t know what was in paper setters mind.

8 questions in the end which didn’t not have negative marking were testing Decision making skills

Maths questions were typical RS agarwal types , you just need to brush up few formulas to solve them

 

What will be my score ?

Seriously i don’t know , exam would be high scoring i feel. People who are preparing for it religiously for this since long would easily crack it.

What are your thoughts? Please post

Excel cell drag plus sign not coming

The explains How to fix the problem when excel cell drag function don’t work or plus sign don’t come when you want to drag the cells in Excel 2010 , 2007 or 2003

All we have to do is to enable one checkbox

  • In Excel 2007: Office Button > Excel Options > Advanced > Editing options: Enable fill handle and cell drag-and-drop
  • In Excel 2003 and earlier: Tools > Options > Edit > Allow cell drag and drop
  • In Excel 2010 Go to File > Options > Advanced > Enable file handle and cell drag-and-drop

Want to see more detailed animation ? Visit the link below

http://reviewofweb.com/how-to/enable-cell-drag-and-drop-excel-2010/

Source code of Java API

To see the source code of Java API the easiest way is to download the corresponding JDK from the Oracle website and follow the steps below.
  • Install the JDK and go to folder where JDK is installed
  • In that folder there would be one zip file named src.zip
  • Extract it and enjoy the source code for Java API

Delhi airport and New Delhi Railway Station

How to go from New Delhi station to International airport or how to go from International airport to New Delhi

To go from New Delhi Metro station to IGI airport Delhi Airport metro Express is the best way ,  it takes about 20 minutes from Delhi Metro station to reach airport. It go to T3 of the airport

The frequency of the train is 20 minutes and it operates from 5 Hrs to 23:00 Hrs (Check latest timings on official website , they can increase running hours)

You can read more about the metro for airport at links below

Delhi Airport Express Home page

Delhi Airport metro express timings Timings and Fare details

 

Delhi airport Terminals

To reach your terminal at International airport from Delhi t3 terminal

Mostly All domestic flights depart from 1D terminal

Terminal 1D : Departure of Indigo , Go Air , Spice

Terminal 1C : Arrival of Go Air , Spice Jet , Indigo

Terminal T3  : International fights , Upper level for Departures , Lower level for Arrivals

A very good list of FAQ about airport is answered here.

To travel from 1D / 1C to T3 the transport is available at airport . Just contact the Inter terminal transport helpdesk.

Setting up EC2 Command Line environment on Windows

This post assumes that you have setup your EC2 account successfully using Amazon Management Console , to obtain Private Key and X502 Certificate. If you are not sure what this mean , just read the other post on getting started with EC2

To setup windows environment for development with Amazon Cloud Computing platform , EC2. We need to follow below steps

  1. Download the command line tools
  2. Setting Up Environment variables and path
  3. Test it

Download

  • Download latest version of JDK from Oracle website
  • Download the latest version of EC2 API tools from Amazon Website

Environment Variables

Set the following environment variables

JAVA_HOME as location to your jdk installation folder (e.g C:\Program Files\Java\jdk1.6.0_25 )

EC2_HOME as location where you unzipped the EC2 API tools ( e.g D:\Development\Tools\ec2-api-tools-1.4.3.0)

EC2_PRIVATE_KEY as location where you stored your private key including name of private key ( e.g D:\Development\Importantcloudfiles\pk.myprivatekey.pem )

EC2_CERT as as location where you stored your cert key including name of cert key (e.g D:\Development\Importantcloudfiles\cert.mycertkey.pem )

Add following information to path variable after the last information present in path variable

;%JAVA_HOME%\bin;%EC2_HOME%\bin

Testing

Open the command prompt and browse to bin folder in EC2 API tools folder

Test by entering following command

ec2-describe-regions

It should show output as below

 

image