CHAPTER 3

image

Get Up and Running with Neo4j

Things are starting to get interesting now. We’ve been over a bit of history, and then got to know Neo4j a little better as well, now it’s time to get started. To start taking advantage of the awesome things Neo4j has to offer, we need to install it first. Whether you use Windows, Mac, or Linux, getting started with Neo4j is really easy. On any of these systems, it’s possible to install Neo4j directly, or potentially by using Vagrant, which is a tool used to create development environments. If you’re unfamiliar with Vagrant, don’t worry, everything will be explained soon enough.

Image Note  Not everybody likes to use virtual environments so to cover all bases whether you use Windows, a Mac, or a flavor of Linux, all of those installation instructions will be covered. If you’re going with a direct approach, then regardless of your operating system, you’ll need to download the code from neo4j.com, so to avoid repetition, let’s get to that. There is also an option to build Neo4j from source, so if you’re interested in doing that, head to the Neo4j github page (github.com/neo4j/neo4j) and you can follow the helpful instructions in their README.md file.

Downloading from Neo4j.com/download

You can use the package downloaded from the Neo4j website regardless of your operating system, however in the case of Ubuntu it’s actually easier to install it using a package. The option to install via the website is still there, so it’s worth covering.

When you head to the page, you can choose from a number of options, most of which are about which of the editions to download. The option to go for here is the Community edition, unless you’re willing to dive into the 30-day free trial for the Enterprise edition, that is. Once you’ve hit the conveniently large green button, you’ll be taken to a download page and your download will start automatically, with a link if it doesn’t work.

Windows users actually get a rather easy installation process, as you actually just receive an .exe file that does all of the hard work for you, but we’ll go through that in a moment. For Mac and Unix, what you’re downloading is a zipped Neo4j environment, ready to run and essentially all you have to do is start the server. Before you can do that though, you’ll have to make sure you have either Oracle JDK 7 or Open JDK 7 installed. In this case JDK stands for Java Development Kit, and in this case, it’s for the Standard Edition.

Conveniently enough, there are actually links to both of these on the download page, which makes things a little easier, although there are alternatives available, which we’ll cover on a per-OS basis.

Once JDK is sorted, you can theoretically run the server, and you’ll be ready to go. Since the steps can be different per system, those will be covered separately, starting with Windows.

Installing on Windows

Installing directly on Windows couldn’t be easier, as the download you receive from the Neo4j website does everything, including dealing with the JDK dependency. If you’re running Windows Enterprise edition, you will need to install JDK, but as mentioned above, you can find a link to that from the download page above. In this case, I’m installing on clean version of Windows 10, but these instructions should also work on other versions, too. If in doubt, check the Neo4j website. Anyway, back to business, this easy installation results in you being able to double click the .exe file to install everything, which is brilliant. You’ll be guided through the installation process and you’ll be prompted to pick an installation location, and after the process is complete, you’ll get the option to run Neo4j.

When you run Neo4j, you’ll see a dialog similar to that in Figure 3-1. The only difference potentially being the path of the database.

9781484212288_Fig03-01.jpg

Figure 3-1. The dialog visible when you start Neo4j on Windows 10

To start the server, just hit the button, then the dialog will change, and the server will be available at http://localhost:7474, which will be shown in the dialog. You’re now up and running with Neo4j, nice and easy!

Installing on Mac

For the sake of keeping things even, this installation will take place on a clean Mac with OS X Yosemite (Version 10.10.3, to be exact) which comes with Java installed, but in this case, that’s not what’s needed. Sadly, there aren’t any easy shortcuts to getting installed on a Mac, it pretty much just comes down to downloading Neo4j, and ensuring your system is able to run it. As I mentioned earlier, you’ll need JDK 7 to run Neo4j, so the first thing to do is check the version you have installed, which you can do via your favorite Terminal application, and pressing:

java -version

This will tell you the version you have installed, if any. If your version isn’t 1.7, then you’ll need to install the correct version in order for Neo4j to run. There are a couple of approaches that can be used here: installing direct via the one of the links from the Neo4j download page, or by using Homebrew. As both are perfectly reasonable choices, and I don’t want to force my will on you (I like the Homebrew option) we’ll go through both, starting with going direct.

Installing from a Website

This approach uses one of the previously mentioned links from the Neo4j download page. It doesn’t matter which approach you go for, but the easier of the two is the Oracle approach, purely because the link provided takes you to the correct place on the website. You’ll need to accept the user agreement for Java SE Development Kit, then download the version for OS X. The file you download is a DMG, so just follow the steps and you’ll soon have JDK installed. One alternative is to use Homebrew, which we’ll go through now.

Going with Homebrew for Java

If you’re unsure of what Homebrew is, or you’re fan of it and like being reminded how great it is, then let’s address both, shall we? Homebrew is a package manager for OS X, which makes installing missing packages from your system easy as pie. One of the first packages I’d always install is the demo one they use, wget. Homebrew’s tagline is “The missing package manager for OS X.”

Essentially, there are a lot of smaller packages that you may need as a developer, and installing them manually is a pain (wget being a great example) so Homebrew tries to make that easier. Each package is stored in its own location on your system, so it can be just as easily removed as it is installed, plus, this means that if there’s a bug in a package you’ve downloaded, you can update it, brilliant! Of course, Homebrew takes care of maintaining the packages. You just install or manage them via commands, it’s easy! The good thing is, you can search Homebrew for different packages as well, so before trying to build something from source or using an installer, check if Homebrew has a tap for it (tap being what they call their package repositories).

Enough chat, let’s install it, which is nice and easy, so there’s nothing to worry about. To get the code needed, it’s best to head over to the website and ensure it’s correct (it’s right at the top), then paste the code into your Terminal window, and it should look something like this:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install")

When you run the command, it’ll give you step by step instructions on how to install it, and soon enough you’ll be done, and ready to move onto the next step, installing Homebrew Cask.

Homebrew Cask

The concept of having a decent package manager on your Mac is great, but one for your extensions is even better, and Homebrew Cask, is what you’re looking for. As I briefly mentioned earlier, Homebrew Cask is an extension of Homebrew, taking the concept and applying it to applications instead. The applications in question are open source and readily available, so you can’t install Photoshop with it, essentially. You can also install things like Java with it, which is why I’m bringing it up now. As with Homebrew itself, you can just search an application (Google Chrome is a common one) and it’ll install it for you, without you having to download anything from the website. Since the Java SDK can be installed this easily (it’s just called Java, but it’s actually the SDK) it’s time to install Homebrew Cask and get moving. The code for Homebrew Cask is actually a cask, so installing it can be done like so:

brew install caskroom/cask/brew-cask

It’s around about 50MB in total, so it may take a little time depending on your connection, but soon enough you’ll have it installed, and now, it’s FINALLY time to install Java. First, the version of Java in Cask may be wrong, so to fix that, run the following:

brew tap caskroom/versions

This updates the versions repository for Java from the caskroom, it’ll download a tiny a package, then you can finally run:

brew cask install java7

This will install the missing Java version and allow you to finally run Neo4j, which is brilliant. Plus with it being managed by Homebrew it can be just as easily removed as it was installed, and it can be updated just as easily, which is brilliant.

With Java Installed

No matter how you’ve installed Java, it’s now installed, which means Neo4j is finally ready to go. Now, all that needs to be done is to `cd` into where you have Neo4j on your system, and run the following:

./bin/neo4j console

This will run the Neo4j server, and it’ll be available for you to see at http://localhost:7474 when it’s finished doing its thing and prints `INFO [API] Remote interface ready and available at [http://localhost:7474/]` to show that it is. You can now have a chance to play with the Browser and get used to where everything is, which is good because you’ll be in here a lot.

Now Neo4j is installed on your system and ready to use. Now, anytime you want to use Neo4j, just `cd` into the directory and run `./bin/neo4j console` then you’re up and running. The first time you visit the Browser, you will be required to authorize the application by logging in, and then by changing your password. The default details are `username: neo4j` and `password: neo4j` but they’re also shown on the screen when you need to login, so it’s easy enough to follow along. Be sure to make a note of the new password, as this will be needed to authenticate any application that needs to access your data, so when using it in production, be sure it’s a secure password.

Installing on Ubuntu

When it comes to installing on Ubuntu (or any other Debian based Linux distribution), there is actually a nice and easy way to get Neo4j installed, which is always a good thing. As mentioned earlier, you could of course use the package downloaded from the Neo4j website, and install Java 1.7, but because Ubuntu doesn’t official support 1.7, it’s a little awkward, but it is still possible. For ease though, we’ll be running through the approach that uses Ubuntu’s package manager, which means you can have Neo4j installed in a few lines. Let’s get started.

The first thing that you’ll need to do is open up a Terminal window, and type `sudo su` which will prompt you for the administrator password. This process logs you in as the root user on the machine which means all commands are run as root/admin. The commands that are required all require root access, so it essentially saves having to put `sudo` in-front of every command. With you now as the root user (there would have been some change to the prompt, potentially) the first command that needs to be run is:

wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add -

This command adds the Neo4j repository key to the package manager, so that when we add where to download Neo4j from, it actually works, by signing the downloads correctly. When the command runs, it’ll download the key from the Neo4j website, then pipe it into `apt-key` so it can be used. The next command on the list is adding where to get Neo4j from, which we do so by running:

echo ’deb http://debian.neo4j.org/repo stable/’ > /etc/apt/sources.list.d/neo4j.list

Running this command will add the Neo4j repository location to the `apt` sources list, so when we go to install it, it’ll now look for Neo4j in the correct place. One thing worth noting here is the word `stable`, as this refers to the build of Neo4j that will be downloaded, and is the recommended version to use. If desired it’s also possible to use the `oldstable` or `testing` builds of Neo4j, but again, it’s recommended that `stable` is used.

With the desired build added, there’s only two steps left, update the system, then install Neo4j. Updating the system is easy, and can be done by:

apt-get update -y

This will install any updates to the system and check all of the repositories in the source list for any updates. When the command has finished, there’s one more left, installing Neo4j, which is done with:

apt-get install neo4j -y

This will take care of downloading the files, and also installing everything. When everything is finished, the Neo4j Browser will be available to you at http://localhost:7474 just like the other solutions. The installation process has installed Neo4j as a service, and it’ll now always run when you start the machine. You can of course start, stop, or even restart the service as often as you like, depending on preference. If you run `service neo4j-service` (or with sudo in front if you aren’t still the root user) the following options are provided: start, stop, status, restart, and force-reload. So if you’d like to restart to the service, just run `service neo4j-service restart` (Don’t forget about sudo, if you need it) and the service will restart itself.

As with the different build of Neo4j that could be used, there’s also the different versions that can be installed as well. The version that has just been installed is the community addition, but advanced and enterprise editions can be installed with `apt-get install neo4j-advanced` and `apt-get install neo4j-enterprise` respectively.

With all of the steps done, that’s it, Neo4j is installed on the system and is ready to use, and with it being installed through the package manager, it means that any updates that come through will automatically be applied, which is always nice.

Install Neo4j in a Vagrant Box

Vagrant is a system for provisioning your application, and allows it to run in a virtual server environment. This means that you have what would be a server, right on your local environment, which makes collaboration, debugging and management a lot easier. You also don’t need to have just one Vagrant box either, multiple different versions can exist on your system. You can even create your own or use others from the community (I have one for Neo4j, for example) which makes being able to jump on and try a new technology a lot easier, because if somebody has already built a vagrant box for the software you want to use then it’s less setup for you, which is great!

I could go on for ages about how good Vagrant is, but it’s time to start getting it installed. There are a number of solutions you can use for creating virtual operating systems and of course Vagrant doesn’t reinvent the wheel on this, it just utilizes those packages that exist, well Virtualbox and VMWare, that is. If you’re unfamiliar with these systems, they allow you to create a virtual environment on your host machine, so you could install Windows on your Mac, for example. Of all the packages it supports, Virtualbox is the favorite, as it’s open source and cross platform, which makes it a good system to depend on.

Since we know Virtualbox is needed, it’s time to install. If you head on over to virtualbox.com to download the latest version for your system. At the time of writing, Vagrant is version 1.7.4 and Virtualbox is supported for versions 4.0.x, 4.1.x, 4.2.x, 4.3.x, and 5.0.x. This pretty much means you should be good to go no matter what version you have, but it’s always best to check the officially supported version on the vagrantup.com website before installing. You can of course install one of the other supported virtualization platforms, which will cause the configuration of the box to be different (we’ll get to that soon) but it should function in the same way.

With the emulation stuff out of the way, it’s time to install Vagrant itself, so you can now head over to vagrantup.com and downloaded the relevant installer for your system, and when it’s all finished, there’s only a couple more steps until you’re up and running. The command to get everything started in Vagrant is to use `vagrant up` which will start an essentially empty server in the directory you use. With additional configuration in the Vagrant file, and the use of something to provision the box, like Puppet or Chef, then you’d have your ready to use server. Thanks to some Blue Peter style magic “Here’s one I made earlier” as I’ve already created and configured a Vagrant box to run Neo4j, which you can get from:

https://github.com/chrisdkemper/neo4j-vagrant

Thanks to it being on Github it’ll always get updated, so if any bugs come up, I can get them fixed, or if any updates come up (feel free to do a pull request) then just do a `git pull` and you’ll be fine. Speaking of `git pull` you’ll need Git to pull down the repository. If you aren’t familiar with Git, it’s a brilliant source control system, and you should really familiarize yourself with it, in case you need to use it. If you’re new to Git, then there’s a number of online resources to get you up to speed, but all you need to pull down from the repository is:

git clone https://github.com/chrisdkemper/neo4j-vagrant.git my-project

This will pull a copy of the code down to your location machine, and just change `my-project` to whichever folder name you’d like. Then when you’re inside you can just do `git pull` to get any updates, and if you make no changes then that’s it. You can of course change the name of the remote, and add a new one for your project code.

With the code now on your machine, all you have to do is run `vagrant up` and the box will begin provision, and when it’s done the server is available at http://localhost:7474.

Summary

Depending on your choice of system, your installation process may have been a lengthy or short one, but either way Neo4j is up and running, and ready to use on your system. Now things are finally starting to get interesting, in the next chapter, we’ll be taking a look at Cypher, and the commands you’ll need to perform certain actions, which is just what you need to get up to speed with it and see how it works.

Although installing on your host system is perfectly fine, if you haven’t tried Vagrant, I’d highly recommend it. I’ve of course given my Vagrant box repository as the example project, however you can use Vagrant to install anything you’d like. You can either write your own or use one from the community. It’s a brilliant resource, and the more people use it (or something similar) the sooner we’ll get rid of the whole “Well, it works on my machine” discussion, which has been going on a little long now.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.27.29