Neo4j installation guide

Neo4j installation guide

After spending some good quality time banging my head against the keyboard, I finally got Neo4j running on my machine – it was quite a bit more of an adventure than the Neo4j website would lead one to believe. This, of course, may have something to do with the fact that I am both on a Windows computer and am still a relative coding/data newbie.

In the interest of lessening frustration all-around, I’ve made two tutorials for how to get Neo4j both installed (the easy part) and actually running (the hard part). The short version is immediately below; try the walkthrough a little farther down if the command line still stresses you out a bit.

There’s also a troubleshooting section at the end of the post, so check that out if you’ve already gotten to the banging-head-against-keyboard stage.

Short version:

Download:

  1. Python
  2. the Python package py2neo
  3. Java
  4. Neo4j (choose the latest community stable release). Extract the folder to somewhere easily accessible.

Configure:

Open the file neo4j-server.properties, which is in the folder %Neo4j%\conf, in a text editor. Find the line org.neo4j.server.database.location=data/graph.db and point to the database you want to access. In my case, this is the Phylet database, so this line reads  org.neo4j.server.database.location=data/phylet.db. If you don’t have a Neo4j database built yet, leave this line as-is.

Start Neo4j server:

In a command prompt window, from the Neo4j directory:

If you are on Linux/Mac, run bin/Neo4j start

If you are on Windows, run bin\Neo4j.bat start

NOTE: If you are on Windows, there is a higher probability that you will get an error when you try to start the server for the first time. If this happens, see the troubleshooting section in the walkthrough.

Access the database:

Open http://localhost:7474 in a browser to see the web user interface.

Walkthrough:

Installing Python

If you already have Python installed on your computer, skip to the section about required Python packages.

  1. Check to see if Python is already installed on your computer; some operating systems (like Mac OS X Mountain Lion) already have Python 2.7 pre-installed. You can check by searching for “Python” in your installed programs; if you see a shortcut to the Python command line pop up, you are good to go – skip to the section on required Python packages.
  2. Download the latest Python 2.7.x release from the Python website. Installation should be straightforward—the installer should take care of itself. Check Python’s “Getting Started” page if you have problems.

NOTE: Be sure to download Python 2.7.x release. There is also a Python 3.3, but a number of Python packages are not compatible with Python 3.3, which will cause problems down the road.

Required Python packages

You will also need two Python packages: json, for parsing data in JSON format, and py2neo, which provides access to Neo4j in Python. The json package is included in the standard Python library and so should already be installed; you will need to download and install py2neo.

Py2neo assumes that you already have a package installer like pip. If you do, install py2neo and skip to the section on installing Java. Otherwise, you will need to install pip first; instructions on how to do so can be found here.

Once pip is installed, type pip install py2neo into a command prompt. If you have not used the command prompt before, it can be accessed if you are using Windows by opening the Start menu and searching for “cmd”; in Mac, by searching for “Terminal.”

Installing Java

  1. Check to see if/which version of Java is installed on your computer. You can do this by typing java –version into the command line, or you can go here to have Java check for you. As of version 1.9, Neo4j supports Java 7 (called Java Runtime Environment or JRE); versions of Neo4j older than 1.9 only support JRE 6. If you have the correct version, skip to the section on installing Neo4j.
  2. Download JRE 7 from here. The Java website should automatically detect the correct version to download. If you are running Neo4j 1.8, be careful – the newest version of JRE may remove JRE from your computer. JRE 6 can be downloaded from here.

NOTE for Windows users: Neo4j sometimes does not detect a Java installation correctly if you run a 32-bit (x86) version of Java on a 64-bit machine. If you get the error message Unable to locate jvm. Could not find HKLM\SOFTWARE\JavaSoft\Java Runtime Environment/CurrentVersion entry in windows registry when you attempt to run Neo4j, this may be the source of the problem. See troubleshooting section below for more information.

Installing Neo4j

  1. Download the latest stable release community version from the Neo4j website.
  2. Unzip the downloaded file and extract it to a directory that will be easy to access again—for example, Desktop or Documents.
  3. Navigate to the Neo4j directory you just extracted and copy the folder with the database you want to use into the \data folder in the main Neo4j directory (from now on, we will refer to this directory as \Neo4j\ in this walkthrough). If you don’t have a Neo4j database yet, skip to the next section on starting the Neo4j server.
  4. Open the file neo4j-server.properties,which is in the folder \Neo4j\conf, in a text editor like Notepad++. Find this line:

org.neo4j.server.database.location=data/graph.db

and change the location to the databases you want to use. I’m using the Phylet database, so this line looks like:

org.neo4j.server.database.location=data/phylet.db

Starting the Neo4j server

  1. Open a command prompt and navigate to the \Neo4j\bin folder.If you are not familiar with the command line, this is a handy reference for commands. The most important one for our purposes is “cd,” which means “change directory.” For example, let’s say you extracted Neo4j to your Documents folder to a folder named Neo4j. To navigate to the Neo4j directory:If you are on Mac/Linux, search for the program Terminal and open it. In this example, you would type cd documents/neo4j/bin.If you are on Windows, click on the Start menu and type “cmd” and press enter. In the prompt window, you will see C:\Users\User>_. In this example, you would type cd documents\neo4j\bin and hit enter.You are now inside the \Neo4j\bin folder.
  2. Type Neo4j start (if you are using Mac/Linux) or Neo4j.bat start (if you are using Windows) and press enter.

If you see something like this, congratulations—Neo4j is up and running! You can skip to the section on accessing the database. Otherwise, you will have to do some troubleshooting. Skip to the troubleshooting section below.

Accessing the database

Go to http://localhost:7474 on your favorite browser to access the Neo4j user interface. Neo4j’s manual that can help you learn the ropes.

Troubleshooting

If you get the error ‘java’ is not recognized as an internal or external command or the error ‘findstr’ is not recognized as an internal or external command:

You are missing some environment variables. To fix this:

      1. Right-click “Computer” (sometimes “My Computer”), either in the Start menu or in Windows Explorer.
      2. Select “Properties.”
      3. Select “Advanced System Settings” (usually in the left pane).
      4. Select “Environment Variables.”
      5. In “User variables,” add the following new variables:
        1. JAVA_HOME as the name and the path to java.exe as the value. Depending on whether you have 32-bit or 64-bit installed, this path may look something like C:\Program Files (x86)\Java\jre7 or C:\Program Files\Java\jre7. Do not include \bin—that is, the value should not look like C:\Program Files (x86)\Java\jre7\bin.
        2. JRE_HOME as the name and the path to java.exe as the value. This should be the same as the value above; again, do not include \bin.
        3. JAVA_PATH as the name and the path to java.exe as the value. In this case, do include \bin. The path should look like so: C:\Program Files (x86)\Java\jre7\bin.
      6. In “System variables,” edit the variable PATH to add the following:
        1. The path to java.exe, including \bin—i.e., C:\Program Files (x86)\Java\jre6\bin
        2. C:\Windows\system32

        Make sure to separate each path with a semicolon.

      7. Close all command prompt windows. Reopen a command prompt, navigate back to the Neo4j\bin folder, and try running Neo4j.bat again.

If you get the error [SC] StartService FAILED 2: The system could not find the file specified:

You may be missing one or more environment variables. First, try the steps above.

If you have all the necessary variables set and are still getting this error:

    1. Open \bin\base.bat in the Neo4j directory in a text editor.
    2. Find these lines (lines 44-45) and delete them:

rem Check classpath

echo “%classpath%” | findstr “SNAPSHOT” > NUL && echo “WARNING! Latest Development Build. Not intended for general-pupose use. May be unstable.”

If you get the error Unable to locate jvm. Could not find HKLM\SOFTWARE\JavaSoft\Java Runtime Environment/CurrentVersion entry in windows registry, and you are sure that you have Java installed:

Neo4j did not look for your Java installation in the right place. This can happen if you have a 64-bit machine and are running a 32-bit version (x86) of Java. Try the steps for explicitly setting the Java environment variables above. If that doesn’t work, try installing the 64-bit version of Java on your computer (download link here). If this doesn’t work either, this thread might have some solutions; this seems to be a bug that has not yet been entirely resolved.

If you get the error Unable to access jarfile windows-service-wrapper-*.jar:

You are on Windows and running Neo4j 1.8.x or earlier.

      1. Open \bin\base.bat in the Neo4j directory in a text editor.
      2. Find this line:

set wrapperJarFilename=windows-service-wrapper-*.jar

and replace it with this line:

set wrapperJarFilename=windows-service-wrapper-4.jar

For further troubleshooting, try Neo4j’s manual or one of the Neo4j forums.

Hope that was helpful! Let me know if there’s more I should add.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s