How to Install Elasticsearch 8 on Ubuntu 22.04 LTS
Ever tried getting a fresh instance of Elasticsearch up and running on a clean Ubuntu 22.04 box? I’ve had that same headache: you download a repo file, run `apt install`, and the service dies before you even get a chance to log in. Below is a straight‑up, step‑by‑step playbook that gets Elasticsearch 8 humming without the usual trial‑and‑error.
Why you might be stuck
I’ve seen this happen after a bad driver update or when an older Java version slips into the PATH. The default `apt` repositories don’t ship Elasticsearch 8; they still point to the old 7.x branch, which breaks on recent Ubuntu releases. That’s why we’ll use Elastic’s own repository and explicitly set up the right JDK.
Install prerequisites
1. Update your package list
sudo apt update
This guarantees you’re pulling the newest metadata from the mirrors.
2. Install curl, gnupg, and ca‑certificates if missing
sudo apt install -y curl gnupg ca-certificates
Those tools let us fetch the signing key safely.
3. Add the official Elastic GPG key
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
Without this, `apt` will refuse to trust packages from the repository.
4. Set up the Elastic 8.x repo
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list > /dev/null
This line tells `apt` where to look for the latest 8.x packages.
5. Refresh your package list again
sudo apt update
Install Elasticsearch 8
sudo apt install -y elasticsearch
The installer pulls in a 17‑JDK from Elastic’s own repository, so you don’t need to juggle `openjdk-17` manually.
After installation the service is already registered with systemd, but it isn’t running yet.
Enable and start the service
sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service sudo systemctl start elasticsearch.service
Running `systemctl status elasticsearch` should show an “active (running)” state. If not, check `/var/log/elasticsearch/elasticsearch.log`; the most common hiccup is a missing or mis‑typed JVM path.
Verify installation
curl -X GET "localhost:9200"
A JSON payload with your cluster name and version will appear. It should contain `"version": { "number":"8.x.x" }`. If you see something else, the wrong repo is probably still in use.
Common pitfalls
- Java not found – Elastic ships its own JDK; make sure no other `java` binaries are in the PATH before running the service.
- Firewall blocks port 9200 – Ubuntu’s default ufw may be active. Open it with:
sudo ufw allow 9200/tcp
- Outdated kernel – If you’re on a very new kernel, some older Elastic binaries might complain about memory page size. Updating to the latest LTS kernel usually fixes that.
Tweaking settings
The default config lives in `/etc/elasticsearch/elasticsearch.yml`. A quick sanity tweak:
# Disable HTTP authentication for local dev only xpack.security.enabled: false # Allow Elasticsearch to bind to all interfaces (useful on a VM) network.host: 0.0.0.0
After editing, restart the service:
sudo systemctl restart elasticsearch.service
TL;DR
1. Add Elastic’s GPG key and repo for 8.x.
2. `apt install elasticsearch`.
3. `systemctl enable && start`.
4. Verify with `curl localhost:9200`.
5. Tweak `/etc/elasticsearch/elasticsearch.yml` if you need remote access.
That’s all there is to it—no fancy Docker tricks, no manual Java installs. Just a clean Ubuntu 22.04 box and a few commands.