Skip to main content

How to Install Solr 8 on macOS 13 Ventura for Drupal Compatibility.

Leer en Español

You might have observed that the solr version included in the most recent homebrew package is 9. However, its schema is currently not compatible with Drupal. Therefore, I will guide you on how to obtain version 8 of solr, which is compatible with Drupal.

Requirements

  1. Homebrew
  2. Java 8

Step 1: Install Java 8 using Homebrew

If you haven't installed Homebrew, you can find the installation instructions at https://brew.sh/. After installing Homebrew, open Terminal and run the following command to install Java 8:

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

Step 2: Find the Java 8 installation path

To find the path of the installed Java 8, run this command in Terminal:

/usr/libexec/java_home -v 1.8

Take note of the output, which should be something like /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home.

Step 3: Set JAVA_HOME environment variable

To set the JAVA_HOME environment variable, open your shell profile file (e.g., ~/.bash_profile, ~/.bashrc, or ~/.zshrc) in a text editor and add the following line, replacing /path/to/java8 with the path you found in step 2:

export JAVA_HOME="/path/to/java8"

For example, if the path from step 2 was /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home, the line you should add to your shell profile is:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"

Save the file and close the text editor.

Step 4: Apply changes

Run the following command to apply the changes to the current session:

source ~/.zshrc

Step 5: Verify Java version

Verify that you're using the correct Java version by running:

java -version

Step 6: Download solr 8

Go to the Apache Solr 8 archive and download the .tgz file for that version.

Extract the downloaded archive: Open Terminal and navigate to the directory where the downloaded .tgz file is located. Extract the contents using the following command:

tar xzf solr-8.9.0.tgz

Replace solr-8.9.0.tgz with the name of the downloaded .tgz file.

Move the extracted directory to a desired location: You can move the extracted directory to a location of your choice. For instance, you can move it to the /opt directory:

sudo mv solr-8.9.0 /opt/solr

Step 7: Set up environment variables

Add the Solr binary to your system's PATH by adding the following line to your shell profile (e.g., ~/.bash_profile, ~/.bashrc, or ~/.zshrc):

export PATH=$PATH:/opt/solr/bin

Save the file, and then run source ~/.bash_profile, source ~/.bashrc, or source ~/.zshrc (depending on which file you edited) to apply the changes immediately.

Step 8: Start Solr

Run the following command in Terminal to start Solr:

solr start

Step 9: Verify Solr installation

Check that Solr is running by opening a web browser and navigating to http://localhost:8983/solr/. You should see the Solr admin dashboard.

Step 10: Create Launch Daemon

Now that solr is installed, you will have to start it everytime you restart the computer, to prevent that, we are going to create a Launch Daemon that will launch the solr service automatically.

Create a plist file

Create a new file called org.apache.solr.plist using a text editor like nano or vim, and add the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.apache.solr</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/solr/bin/solr</string>
        <string>start</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/opt/solr/logs/solr.log</string>
    <key>StandardOutPath</key>
    <string>/opt/solr/logs/solr.log</string>
    <key>WorkingDirectory</key>
    <string>/opt/solr</string>
</dict>
</plist>

Move the plist file to the LaunchAgents folder

Copy the org.apache.solr.plist file to the ~/Library/LaunchAgents/ folder:

cp org.apache.solr.plist ~/Library/LaunchAgents/

Load the launch agent

Load the plist file to launchd:

launchctl load ~/Library/LaunchAgents/org.apache.solr.plist

Now, Solr should start automatically whenever you log in to your user account. If you want to stop Solr from starting automatically, you can unload the plist file:

launchctl unload ~/Library/LaunchAgents/org.apache.solr.plist
comments powered by Disqus