How to Update Magento 2 to the Latest Version?

The Magento team regularly releases new versions with stunning features, fixes and security improvements. It's meant to secure your store from security threats, boost functionality and improve performance. But it won't work for you, unless you update Magento 2 timely. 

Some delay the update out of fear of the complicated update process. Some want to avoid the expenses following the update. Some just don't see why they need to update if everything works fine. In any case, you put your store at risk, by running on an outdated version of Magento. 

In this guide, we aim to get you one step closer to Magento 2 update. You'll go through the Magento 2 upgrade process step by step: from creating a backup to fixing the issues that might pop up after the update. 


Why Do You Need to Update Magento 2?

Those of you who still doubt whether to update Magento 2 to the latest version, might need to skim through the following benefits.

  • Improved performance — a new version of Magento is optimised for speed and performance which contributes to better loading times and user experience in your store.
  • Enhanced security — a Magento 2 upgrade brings plenty of security fixes that rescue your store's vulnerability to cyber attacks, hacks and other instabilities. 
  • New features — Magento team often introduces a few new features in the latest versions to improve different areas of your store.
  • Fixed issues — updating to the latest version of Magento allows you to fix existing issues that prevent your store from running properly.

Before you Update Magento 2

Before you update Magento you need to make sure the transition is seamless and doesn't interrupt the shopping process for your customers. So you need to ensure that by creating backups and enabling the maintenance mode. 

Create a backup

To have a piece of mind when updating Magento and ensure data safety during the upgrade, you need to create a backup. It allows you to recover your store to the previous point faster in case something goes wrong during the upgrade. 

You can create backups in Magento using the native Magento tool or a third-party backup tool. In any case, make sure you create a backup before updating Magento.

Enable maintenance mode

As you might know, Magento has different modes, dedicated to different stages of your store. Correspondingly, when you update Magento 2 to the latest version you need to enable the maintenance mode.

It prevents disruption in the customers' shopping experience while you update your store.

How to Update Magento 2 to the Latest Version?

Once you take all the precautions before updating Magento 2, you are ready to start the update. However, you also need to choose how to update Magento. There are three different methods.

Update Magento Using Composer

Composer update is one of the best ways to upgrade Magento.

Note: you need to enable the maintenance mode before updating Magento via composer.

1. Require Magento by running the following command:

composer require magento/product-community-edition 2.4.x --no-update
composer update

Replace x with the Magento version and product-community-edition with the Magento package you're upgrading to.

2. Run the upgrade commands to complete the process:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento setup:di:compile
php bin/magento indexer:reindex

3. Check the Magento version to ensure the update has been completed successfully. You can use the following command:

php bin/magento --version

Update Magento Manually

Although it is preferred to upgrade Magento via composer, you can also do that manually. Simply upload the latest Magento 2 version to the root directory. 

1. Download the latest Magento version and upload it to the root directory. 

Note: if the system asks you to replace existing files, choose Yes

2. Run the upgrade commands to complete the process:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento indexer:reindex

This will update all dependencies, refresh the database and flush caches. 

3. Go to the frontend and backend to check if the update has been run smoothly.

Update Magento Using Web Setup Wizard

Note: updating Magento 2 this way only applies to those tho use older versions of Magento. Starting from Magento 2.4.x the WeSetUp Wizard has been terminated.

1. Navigate to System > Tools > Web Setup Wizard and find the Magento 2 Web Setup Wizard.

2.  Click on the System Configuration and add the authentication keys from your Magento account. Then save the configuration. 

3. Click the System Upgrade to update the Magento 2 version. 

That's how you upgrade Magento to the latest version, using these three simple methods. However, the process is still not finished.

Most Common Magento Upgrade Mistakes

Once you upgrade Magento version, and check it on the frontend and backed you might encounter some errors. 

So, we've gathered some of the most common ones below to help you troubleshoot and fix them.

Component Dependency Conflicts

Component dependency conflict after the Magento upgrade usually arises from incorrect edits to the JSON composer file. Or it could also be that some third-party extensions rely on the previous components. Either way, it's crucial to fix them to ensure a successful upgrade.

Fix: you can start by restoring the JSON compose file so it reflects the necessary dependencies accurately. Besides, you need to check if the module, causing the issue, needs updating too, and install its latest version.

"Cannot Create the Directory" Error

This is a common issue appearing during the Magento update. It happens due to permission issues with files and directories in the Magento var subdirectory.

Fix: run the php bin/magento setup:di:compile command to ensure all the files and directors have the right permissions.

"Cannot Allocate Memory" Error

If the system has executed all the memory or swapped space, you'll encounter the "Cannot Allocate Memory" issue. So the fix usually requires optimizing the Magento memory usage.

Fix: find extensions that consume excessive memory and make improvements. You can also consider upgrading your server RAM or detecting memory leaks and fixing them.

Magento 2 Upgrade Service

Once you follow all the steps to update Magento 2 to the latest version, you'll be able to perform it successfully. Nonetheless, if you're not a technical person or want to upgrade Magento Open Source to Commerce, you'll need some help. 

Send us a quick note and our team of dedicated developers will update your Magento 2 store for you.