Running Neo4j on Google Cloud Shell

Install Neo4j from tarball

  • wget -O neo4j-community-5.5.0-unix.tar.gz ‘https://neo4j.com/artifact.php?name=neo4j-community-5.5.0-unix.tar.gz’
  • tar -xf neo4j-community-5.5.0-unix.tar.gz
  • set PATH and NEO4J_HOME
    • export NEO4J_HOME=~/neo4j-community-5.5.0
    • export PATH=$NEO4J_HOME/bin:$PATH
  • start neo4j – $ neo4j start
neo4j on cloud shell

Installing Neo4j on Google Colab

  • install java 17
  • get latest neo4j community edition
  • run neo4j
# install java
!apt-get install openjdk-17-jdk-headless -qq > /dev/null
import os
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-17-openjdk-amd64"
!update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/jre/bin/java
!java -version

# get neo4j and set environment varibles
!wget -O neo4j-community-5.5.0-unix.tar.gz 'https://neo4j.com/artifact.php?name=neo4j-community-5.5.0-unix.tar.gz'
!tar -xf neo4j-community-5.5.0-unix.tar.gz

# environment  variables
os.environ["NEO4J_HOME"] = "/content/neo4j-community-5.5.0"
os.environ["PATH"] = "/content/neo4j-community-5.5.0/bin"+ os.pathsep + os.environ["PATH"]

# set password 
!neo4j-admin dbms set-initial-password password! --require-password-change

# start neo4j
!neo4j start

# install py2neo package
!pip install py2neo
# find hostname
!hostname -I

Example

from py2neo import Graph
graph = Graph("bolt://172.28.0.12:7687", auth=("neo4j", "password!"))
res = graph.run("UNWIND range(1, 3) AS n RETURN n, n * n as n_sq")
for r in res:
    print(r)

Installing Elasticsearch on Google Colab

%%bash
apt-get install openjdk-17-jdk-headless -qq > /dev/null
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/jre/bin/java

rm -rf elasticsearch*
wget -q https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.1-linux-x86_64.tar.gz
tar -xzf elasticsearch-8.11.1-linux-x86_64.tar.gz
sudo chown -R daemon:daemon elasticsearch-8.11.1/
umount /sys/fs/cgroup
apt install cgroup-tools
%%bash -bg
# run it in background  - %%bash --bg
sudo -H -u daemon elasticsearch-8.11.1/bin/elasticsearch 

Notes

Run both elasticsearch and neo4j without login user id and password. For this you need to uncomment or edit few directives in config/elasticsearch.yml and conf/neo4j.conf respectively.

Neo4j

# uncomment the following directives
#dbms.security.auth_enabled=false
#server.default_listen_address=0.0.0.0

Eleasticsearch

# Enable security features - set it to false
xpack.security.enabled: true