Using Neo4j on Windows

By Charlotte

In the old days, Neo4j used to come with an .exe to install/run it, personally I’ve never used it, as it was (in my view) awkward to find all the file locations, so I’ve always used the Zip download.

For a while now, you’ve only had the option of the Zip version of Neo4j, so looks like everyone is in my box now! This is good news, the zip version provides a lot more options and control for the user. But, there’s not a whole lot of documentation about how to use it, aside from ‘run neo4j.bat’.

I actually have a collection of shortcuts I use for my Neo4j instances:

image

It makes it super easy for me to start up an instance on demand, but also have multiple instances – also I get groovy icons – which is better than the bog standard ‘console’ icon.

How do you get this?

Of course you want the icons, the ease of use of Neo4j is simply a bonus. First off – I don’t install Neo4j as a service – when I’m developing against Neo, I don’t really want to have to navigate the ‘Services’ dialog everytime I want to start / stop the DB – nor indeed have to open up a shell to do it.

Script for the win

I have a Powershell script – usually titled something like:

Community 3.3.0 – 7474.ps1

So I can know what edition I’m using, what version and finally what port I have Neo4j setup to run on. But what’s inside that file?

#Set the execution policy so we can import the Neo4j Management Module
Set-ExecutionPolicy ByPass

#Import the module
Import-Module D:\Databases\Neo4j\Community\neo4j-community-3.3.0\bin\Neo4j-Management.psd1

#Start the database
Invoke-Neo4j Console

Only 3 lines, and the comments make it pretty obvious – in the last line I invoke Neo4j in it’s Console mode – this means you’ll be able to CTRL+C the window to shut down the DB – and you can also read the messages from the DB as a bonus.

By changing the port numbers in the Neo4j config files, I can run as many instances of Neo as I have ports at the same time. I usually find this handy if I’m doing a comparison between versions – or someone has asked me a question and I want to test out my answer in a sandbox environment.

So far, so good – at the moment we can open up PowerShell and run the script – which will start the instance, but ideally we just want to be able to double click on a shortcut to run the script file.

So, let’s right click and create a new Shortcut:

image

For the location – we want:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "D:\Databases\Neo4J\Community 3.3.0 - 7474.ps1"

image

This tells PowerShell to execute the script file in a separate window. Press ‘Next’ and give it a name that makes sense – I stick with the ‘Edition’, ‘Version’ and ‘Port’

image

Press Finish, and now you can double click it and run the DB

image

You need to run it as an administrator – as we load in the powershell files, so right click on the shortcut and select properties:

image

Click on ‘advanced’:

image

Then select the ‘Run as administrator’ checkbox:

image

Press OK, then ‘Apply’.

You’re all set now – unless you want to change the icon, in which case, find an icon you like (either built in Windows ones, or google for it) and press the ‘Change Icon’ button, and select it. Easy.

If you want to add that icon to your start menu (windows 10) I find it easiest to right click on an existing application icon in your start menu, select ‘More’ and then ‘Open File Location’:

image

Then copy/paste your new short cut in there, (I put it in a ‘Neo4j’ folder), and finally press ‘Start’ and search for your new icon:

image

Right click on it and pin to the the start menu as you would normally.(No picture as my short cut for that is WIN+S and that keeps on closing the start menu – and quite frankly I’m not changing it for this limited situation).

image