online learning, blog, anil singh



Feb 21

Neo4j Basics Primer Series - Step 1

Objective: Setup Neo4j on your workstation.

Prerequisite: Hunger to learn.


Google, Facebook, Twitter, LinkedIn......are an important part of our lives today. Ever thought of the database  on which these applications run? Some aspects, if not all, of these applications run on proprietary GRAPH database technologies.  How about doing a hands on one such database technology, Neo4j.

Neo4j might not be the most popular database, but it tops the list as the first among the Graph Databases. Check for the rankings. So that means you would be laying your hands again on a technology that is very relevant in the current market place!!! I see that gleam in your eyes.

Keeping with the spirits of 'Basics Primer Series', this series too is aimed to be an authoritative, step-by-step reference guide for a non-starter who wishes to embark on the journey to learn Neo4j.  The series will safeguard the learner from the information deluge on the subject, which might leave him perplexed. This guide will take a very structured approach in disseminating  the information.

Let us kickstart,


What do we need to setup up a working Neo4j environment,

  1. Identify the platform that you are on. I personally prefer to work on Ubuntu. Not for the reason that it's free, but most of the production installations are on one or the other Unix flavours that match very closely to Ubuntu, besides, the Long Term Support (LTS) that you get on Ubuntu is quite inviting. I use Ubuntu 14.04. To the undergrads who are reading this primer, I would highly recommend using a Linux flavour of their choice for the reasons that they would really appreciate when they would be into their careers. In case you have a windows machine, you can run Ubuntu on a virtual machine using Oracle Virtual Box or VMWare Player.
  2. Download a copy of the latest Neo4j for Ubuntu. It is always good to learn on the latest GA release, the current one is 2.3.2. A Community Edition is good to start with. It doesn't have the scalability and other advanced features required for a Production worthy setup, but then these are quite non-essential for this basic series.
  3. Starting the Database Server,
    1. Open the Terminal window (Ctrl + Alt + T). Unzip and untar the downloaded archive - $ tar -zxvf neo4j-community-2.3.2-unix.tar.gz - You get a directory 'neo4j-community-2.3.2'. This directory contains all the Neo4j binaries, jars etc.
    2. Move it to your home directory - $ mv neo4j-community-2.3.2 ~
    3. Update the PATH variable with location to Neo4j executables - $ echo export PATH=$PATH:~/neo4j-community-2.3.2/bin >> ~/.bashrc - This will enable you to run Neo4j programs and utilities from any location on the shell.
    4. Make the new setting effective either by re-opening the Terminal window or run - $ source ~/.bashrc
    5. Run the database server - $ neo4j start - A database server process spawns out.
    6. Check the server status - $ neo4j status - You should get the message 'Neo4j Server is running at pid <pid number>', if everything went well.
  4. Connecting to the Database Server
    1. Click here or type in 'http://localhost:7474'  in your browser window. This is Neo4j Browser. You can run your queries as well as visualize the results in colorful Graphs.
    2. On the web page, key-in the Username/ password -- neo4j/neo4j and change the password.
    3. An alternate method of connecting to the database server is using Neo4j shell - $ neo4j-shell - Starts the shell. I recommend using the Neo4j Browser during the initial learning phase as it helps relate to the basic concepts of the database - Nodes, Relationships, Labels, Properties - faster than when using the bare bones but effective shell.
  5. Using Neo4j Browser and the first steps
    1. The Neo4j Browser is rich in features. For now I would limit our discussion to the Editor and the Run/Play button. Look at the screenshot below, you type  your queries in the area marked as 'Editor' and press the button marked as 'Run' to execute the query. 01_Browser
    2. Simplifying get you some glimpse into the look and feel of how to work on data modeling in Neo4j, let me represent Students studying in various Grades, in Neo4j. Copy, Paste and Run each of the statements in the file SampleData in Neo4j Browser Editor. The statements must be run one at a time.The file contains Cypher (equivalent of SQL in RDBMS) queries to create a sample data set in order to give you a sneak peak into the Neo4j world. You might get surprised to see the circles and arrows getting created with each successful execution of the queries, but wait little more for the BIG PICTURE to come ALIVE!!.
  6. The BIG PICTURE, now that you have a sample data set to work on, it's time to look at it. In the Neo4j Browser Editor run - match (n) return n; - This is a Cypher equivalent of SQL 'select * from <table name>' in RDBMS. It displays all the Nodes (Student and Grade) and Relationships (StudiesIn) in the database. 02_Data

Did you see the connectedness in data? The relationship 'StudiesIn' is quite evident even when you are looking into the data and not a design diagram. Relationships are first-class citizens of the graph data model. This is what makes GRAPH DATABASE stand out when it comes to dealing with the connected data. Graph databases are the database of choice when it comes to areas like Routing, Bio-Informatics, Social Relationships, E-Commerce etc.

I hope you got a kick from this brief startup on Neo4j. In the Step 2 of this series, I will take you through the concepts and how to write Cypher queries. Till then, for the curious minds, now that you have setup your Neo4j environment, start tinkering and I will catchup soon.



Recommended for further reading,

  1. Neo4j concepts
  2. Read about Cypher



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>