How to Install Typesense on a DigitalOcean Droplet with Ubuntu LTS

TutorialsServersHostingDatabases
How to Install Typesense on a DigitalOcean Droplet with Ubuntu LTS

December 30, 2024

When your website or application needs a fast and highly customizable search engine, Typesense can be a great option. In this article, I’ll explain how to create a Droplet on DigitalOcean and set up Typesense on an Ubuntu LTS environment quickly and easily.

1. Why Use DigitalOcean and Ubuntu LTS?

DigitalOcean offers an intuitive control panel and reliable infrastructure for deploying virtual servers (Droplets). Meanwhile, Ubuntu LTS (Long Term Support) guarantees security updates and stability for five years, making it ideal for production environments.

2. Creating a Droplet on DigitalOcean

  1. Sign In

  2. Create a New Droplet

    • In the dashboard, click Create > Droplets.
    • Choose the Ubuntu LTS image (e.g., 22.04 or the latest available LTS).
    • Pick a plan with at least 2 GB of RAM for optimal performance.
  3. Configure Access and Firewall

    • Add your SSH key for passwordless connections.
    • Give your Droplet a name, such as typesense-droplet.
    • In Networking > Firewalls, make sure to open port 22 (SSH) and, if needed, ports 80 (HTTP) and 443 (HTTPS).
    • If you plan to make Typesense accessible over the internet, allow port 8108 (or the one you’ll use in your setup).
  4. Create the Droplet

    • Click Create Droplet and wait a few minutes for the process to complete.

3. Installing Typesense on Ubuntu

  1. SSH into the Droplet
    From your local terminal, connect to the Droplet:

    ssh root@<YOUR_DROPLET_IP>
    

    (Replace root with another username if applicable.)

  2. Update the System
    Once you’re logged in, run:

    sudo apt update && sudo apt upgrade -y
    

    This ensures you have the latest patches and updates.

  3. Download the Typesense Package
    Visit the official Typesense page to find the available version. For instance, if the version is 27.1, download the .deb package:

    curl -O https://dl.typesense.org/releases/27.1/typesense-server-27.1-amd64.deb
    
  4. Install the Package
    Use dpkg to install:

    sudo dpkg -i typesense-server-27.1-amd64.deb
    

    If you encounter missing dependencies, fix them with:

    sudo apt-get install -f
    
  5. Verify the Installation
    Check the binary path:

    which typesense-server
    

    It should show something like /usr/bin/typesense-server.

  6. Configure Typesense

    • Create (or edit) the config file at /etc/typesense/typesense-server.ini:
      [server]
      api-key = YOUR_SECURE_API_KEY
      listen-port = 8108
      data-dir = /var/lib/typesense
      
    • Replace YOUR_SECURE_API_KEY with a secure key of your choice.
    • Adjust the port if you prefer something other than 8108.
  7. Prepare the Data Directory

    sudo mkdir -p /var/lib/typesense
    sudo chown -R root:root /var/lib/typesense
    

    Make sure the user running Typesense has the proper read/write access.

  8. Start the Service
    Check if the typesense-server service was created:

    systemctl status typesense-server
    

    If it shows active (running), you’re all set. Otherwise:

    sudo systemctl start typesense-server
    sudo systemctl enable typesense-server
    

    This ensures that Typesense automatically starts on server reboot.

  9. Configure the Firewall

    • If you want the server to accept external connections on 8108, you need to open that port in DigitalOcean’s firewall.
    • If you use ufw on the Droplet, run:
      sudo ufw allow 8108/tcp
      sudo ufw reload
      

4. Testing the Setup

To verify that Typesense is running, use:

curl http://localhost:8108/health

You should see a JSON response indicating that Typesense is operational.

Conclusion

That’s it! By following these steps, you’ve installed Typesense on a DigitalOcean Droplet running Ubuntu LTS. You now have a search engine infrastructure ready for indexing, scalability, and customization. Feel free to tweak your queries, fine-tune relevancy, and get the most out of Typesense.


I hope this guide has been helpful. If you have any questions or want to share your experience, drop a comment below! Happy searching!