Uninstall or reinstall Magento

First steps

  1. Log in to the Magento server as, or switch to, a user with permissions to write to the Magento file system. See switch to the Magento file system owner.

    If you use the bash shell, you can use the following syntax to switch to the Magento file system owner and enter the command at the same time:

    1
    
    su <Magento file system owner> -s /bin/bash -c <command>
    

    If the Magento file system owner does not allow logins, you can do the following:

    1
    
    sudo -u <Magento file system owner>  <command>
    
  2. To run Magento commands from any directory, add <magento_root>/bin to your system PATH.

    Because shells have differing syntax, consult a reference like unix.stackexchange.com.

    Sample bash shell for CentOS:

    1
    
    export PATH=$PATH:/var/www/html/magento2/bin
    

    Optionally, you can run the commands in the following ways:

    • cd <magento_root>/bin and run them as ./magento <command name>
    • <magento_root>/bin/magento <command name>
    • <magento_root> is a subdirectory of your web server docroot. Need help locating the docroot?

In addition to the command arguments discussed here, see Common arguments.

Prerequisites

Before you use these commands, you must install the Magento software.

Update the Magento software

To update the Magento software:

  • If you installed the software from an archive or if you used ‘composer-create-project’, use the Component Manager or System Upgrade utilities.
  • If you are a contributing developer (that is, you used git clone), see Contributing developers—update, reinstall Magento.

Reinstall the Magento software

The way you reinstall the Magento application from the command line depends on your role:

Uninstall the Magento software

Uninstalling the Magento software drops and restores the database, removes the deployment configuration, and clears directories under var.

To uninstall the Magento software, enter the following command:

1
bin/magento setup:uninstall

The following message displays to confirm a successful uninstallation:

1
[SUCCESS]: Magento uninstallation complete.

Optionally keeping generated files

By default, bin/magento setup:upgrade clears compiled code and the cache. Typically, you use bin/magento setup:upgrade to update components and each component can require different compiled classes.

However, in some situations (particularly, deploying Magento to production), you might wish to avoid clearing compiled code because it can take some time. (The cache is still cleared.) To update the Magento database schema and data without clearing compiled code, enter:

1
bin/magento setup:upgrade --keep-generated

The optional --keep-generated option should be used only in limited circumstances by experienced system integrators. This option should never be used in a development environment. Improper use of this optional parameter can cause errors during code execution.

Install the Magento software