Holt DevOps News

Update Magento 2 via CLI

News Categories: MagentoServer HelpTech

This article was published on: 06/26/21 6:40 AM

Update Magento 2 via CLI

First thing is to back up the server / data before driving in


Put the site in maintenance mode

bin/magento maintenance:enable


If you do not have composer installed, no would be a good time ๐Ÿ™‚ – To install the plugin:

composer require magento/composer-root-update-plugin=~1.0 --no-update


If the composer runs out of memory you can try

COMPOSER_MEMORY_LIMIT=-1 composer update


We now need to make a backup of the composer json file by running this command

cp composer.json composer.json.bak


We now need to install the version of magento we are updating too, in our case its 2.4 so we run this command

composer require magento/product-community-edition=2.4.0 --no-update


To see the full list of magento 2.4 versions available we can use the following

composer show magento/product-community-edition 2.4.* --all | grep -m 1 versions


Right, lets get the update installed and fingers crossed there isnt any minor issues.

composer update

Remember if the composer runs out of memory use the following command to overwrite this: COMPOSER_MEMORY_LIMIT=-1 composer update


Allow the the update to run through all the checks and then updates – keep an eye out for anything that fails.


Once the composer has finished updating without any issues we can then proceed to the clean up the install and start running the new Magento 2 version:


rm -rf var/cache/*

rm -rf var/page_cache/*

rm -rf generated/code/*


Next to update the database schema to work with the new M2 version

bin/magento setup:upgrade

If the following error pops up like the composer php error we can run
=php -d memory_limit=-1 bin/magento setup:upgrade

If you have the elasticsearch error you can follow this guide to install: https://devdocs.magento.com/guides/v2.4/install-gde/prereq/elasticsearch.html

Also checkout the official elasticsearch install – this is for Linux servers: https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html#rpm-repo

bin/magento maintenance:disable

and relax, well done you have completed the magento 2.3 to 2.4 upgrade ๐Ÿ™‚

If your frontend is still showing the error you can try and clear all the cache files again as this has happened to us a few times.

Also if you do not receive the 2 factor email and you are locked out of the admin panel please run the following command.


bin/magento module:disable Magento_TwoFactorAuth


php -d memory_limit=-1ย  bin/magento module:disable Magento_TwoFactorAuth


Let's build a better web together

Get in touch with us for a quick quote

Web Development Agency, We Website Design

Weโ€™re eCommerce Experts in Cutting-edge Design & Development Technologies - Worldwide accreditation from leading digital platform providers including Shopify, WordPress & Magento.

Web Development Agency Manchester

Woolden Road
M44 5JX

Web Development Agency London

71-75 Shelton Street
Covent Garden

Let's hook up


0161 676 8989

Stalk Us On Social

What We Do

  • Shopify
  • WordPress
  • Magento
  • SEO
  • Aero Commerce
  • Shopify 2.0

Copyright 2022 We Agency - White Label Web Development Digital Agency.
Registered in England & Wales We Agency is a trading division of We Website Design Ltd. Company Registration Number 14175442 Privacy Policy

Ready to work with us?

Drop us your details and we will arrange a social distanced meet & greet or video chat so you can see our beautiful faces.