How to upgrade Magento 2 from the command line

Upgrading Magento 2 from the command line is a straightforward process. Here’s a step-by-step guide on how to upgrade Magento 2 from the command line:

  1. Backup your Magento 2 site files and database to ensure you have a restore point in case something goes wrong during the upgrade process.
  2. Connect to your server via SSH.
  3. Navigate to your Magento 2 root directory using the cd command.
  4. Put your site into maintenance mode by running the following command:
    bash
    bin/magento maintenance:enable
  5. Check for updates by running the following command:
    sql
    composer update

    This command will check for available updates for your Magento 2 installation and its dependencies.

  6. Upgrade to the latest version by running the following command:
    lua
    composer require magento/product-community-edition=X.X.X --no-update

    Replace X.X.X with the version number you want to upgrade to. This command will update the composer.json file to require the new version of Magento 2.

  7. Run the following command to update the composer.lock file:
    sql
    composer update

    This command will download and install the latest version of Magento 2 and its dependencies.

  8. Update the database schema and data by running the following command:
    python
    bin/magento setup:upgrade
  9. Re-compile your code by running the following command:
    python
    bin/magento setup:di:compile
  10. Clear the cache by running the following command:
python
bin/magento cache:flush
  1. Disable maintenance mode by running the following command:
bash
bin/magento maintenance:disable

Your Magento 2 site should now be upgraded to the latest version. You can verify the version number by logging into the Magento 2 admin panel and checking the footer of the page.