To install Elasticsearch on Ubuntu 22.04, add Elastic's signed APT repository, run sudo apt install elasticsearch, enable the systemd service, and query it over HTTPS. Elasticsearch 8.x and newer ship with a bundled JDK, so you do not install Java separately, and security (TLS and a password for the elastic user) is configured automatically on first install.
The old approach of installing OpenJDK 11, using apt-key add and pointing at the 7.x repository no longer applies. apt-key is deprecated, and 7.x is an old release line. This guide uses a keyring file and the current major version.
You need:
artifacts.elastic.co.apt-transport-https, curl and gpg packages (usually present already).Download the Elastic signing key into a dedicated keyring instead of using the deprecated apt-key:
Then add the repository and tie it to that key with signed-by:
Replace 8.x with the major version you want to run. Check Elastic's installation documentation for the currently supported major versions before you pick one, and keep the whole cluster on the same major version.
Update the package index and install the package:
Near the end of the output, the installer prints a generated password for the built-in elastic user and some security notes. Copy the password now. If you lose it, reset it later:
Reload systemd, enable the service at boot and start it:
Use systemctl rather than the legacy service command, so the unit behaves the same on every systemd-based distribution. The first start can take a short while.
Elasticsearch 8.x enables TLS by default, so a plain http://localhost:9200 request fails. Use the generated CA certificate and the elastic password:
Enter the password when prompted. A healthy node returns JSON similar to this:
You can also check cluster health:
A single-node setup normally reports green or yellow. yellow means replica shards cannot be assigned because there is only one node, which is expected.
The main configuration file is /etc/elasticsearch/elasticsearch.yml. For a single local node, the defaults work. Common changes:
By default Elasticsearch listens on localhost only. If you set network.host to a public address, Elasticsearch enforces bootstrap checks and you must treat the node as a production system with firewall rules and TLS.
To set the JVM heap, add a file under /etc/elasticsearch/jvm.options.d/ instead of editing jvm.options:
Keep -Xms and -Xmx equal. Restart the service after any change:
ufw or your cloud security group.elastic superuser.sudo journalctl -u elasticsearch -f and in /var/log/elasticsearch/.If you only need Elasticsearch for local development, running the official Docker image is often simpler, but the APT package is the better fit for a long-lived server.
Not for 7.x and later. The packages include a bundled OpenJDK, which Elastic tests with that release. Installing your own JDK is only needed if you deliberately set ES_JAVA_HOME.
Since 8.0, security is on by default, so the endpoint uses HTTPS and requires credentials. Use https://, pass --cacert with the generated http_ca.crt, and authenticate as elastic.
It is printed once during installation. If you missed it, run elasticsearch-reset-password -u elastic from /usr/share/elasticsearch/bin.
Back up with snapshots, read the release notes and upgrade guide, then upgrade nodes with the supported rolling procedure. Never jump across major versions without checking the documented upgrade path.
Add Elastic's repository with a keyring and signed-by, install the elasticsearch package, save the generated elastic password, and enable the service with systemctl. Test with HTTPS using the generated CA certificate. Keep the node on localhost or behind a firewall, set the heap in jvm.options.d, and use API keys for applications.