How to Upgrade Magento 2 via command line
You can upgrade or update your current Magento version to a specific higher version using composer and the command line.
You can even simplify your upgrade through professional Magento 2 upgrade services.
For that, you have to open the terminal/command prompt.
After that, go to your Magento site’s root directory in the terminal using cd command
For example, your Magento site can be in a folder/directory path as /var/www/html.
So, go to that directory from the command line, and after that, check your current Magento version with the following command.
php bin/magento --version
Running the above command will output something like this:
Magento CLI version 2.1.7
The above output shows that your current Magento version is 2.1.7.
Now if, you want to upgrade your Magento site to version 2.1.8.
For that, you have to run the following commands:
Note that, you have to be in your Magento’s directory root while running the commands below.
First Step -> Put your site into maintenance mode.
php bin/magento maintenance:enable
Second Step -> Take a backup of the composer.json
cp composer.json composer.json.bak
Third Step -> Install the Composer update plugin
composer require magento/composer-root-update-plugin ~2.0 --no-update
(Run this command, if you are using PHP 7.3 or above)
composer require magento/composer-root-update-plugin ~1.0 --no-update
(Run this command, if you are using PHP 7.2 or lower)
Fourth Step -> Update Magento version in composer.json file using the below command. You can type any required Magento version.
composer require-commerce magento/product-community-edition <Magento version> --no-update
(example: composer require-commerce magento/product-community-edition 2.1.8 –no-update )
Fifth Step -> Update dependencies using the following command.
composer update
Sixth Step -> Execute the following commands.
rm -rf var/di var/generation php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento: setup:static-content:deploy php bin/magento indexer:reindex php bin/magento cache:flush
Seventh Step -> Disable the maintenance mode
php bin/magento maintenance:disable
After the upgrade, again check your Magento version with the following command:
php bin/magento --version
Output showing :
Magento CLI version 2.1.8
For technical assistance, please get in touch with us via email at support@webkul.com
Additionally, explore a wide range of solutions to upgrade your store’s functionality by visiting the Magento 2 Modules section.
For expert guidance or custom feature development, hire experienced Magento 2 developers for your project.