Step-1:Check the Elastic Search Version on your machine.

        curl 'localhost:9200'
The output will be like this:
{
  "name" : "***********",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "******",
  "version" : {
    "number" : "7.10.2",      //  << ----- version
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Step-2:For Elastic Search 6: execute the below command.
php bin/magento setup:install --search-engine=elasticsearch6 --elasticsearch-host="localhost" --elasticsearch-port=9200
for Elastic Search 7 (just update the version)
php bin/magento setup:install --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200