Uninstall themes Composer packages

Prerequisite

Before you use this command, you must know the relative path to your theme. Themes are located in a subdirectory of <your Magento install dir>/app/design/<area name>. You must specify the path to the theme starting with the area, which is either frontend (for storefront themes) or adminhtml (for Magento Admin themes).

For example, the path to the Luma theme provided with Magento 2 is frontend/Magento/luma.

For more information about themes, see Magento theme structure.

Overview of uninstalling themes

This section discusses how to uninstall one or more themes, optionally including the themes’ code from the file system. You can create backups first so you can restore the data at a later time.

This command uninstalls only themes that are specified in composer.json; in other words, themes that are provided as Composer packages. If your theme is not a Composer package, you must uninstall it manually by:

First steps

  1. Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.

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

    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:

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

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

    bash shell example for CentOS:

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

You can also run the commands in the following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

<your Magento install dir> is a subdirectory of your web server's docroot. Need help locating the docroot? Click here.

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

Uninstall themes

Command usage:

magento theme:uninstall [--backup-code] [-c|--clear-static-content] {theme path} ... {theme path}

where

  • {theme path} is the relative path to the theme, starting with the area name. For example, the path to the Blank theme supplied with Magento 2 is frontend/Magento/blank.
  • --backup-code backs up the Magento 2 codebase as discussed in the paragraphs that follow.
  • --clear-static-content cleans generated static view files, which is necessary to cause static view files to display properly.

The command performs the following tasks:

  1. Verifies that the specified theme paths exist; if not, the command terminates.
  2. Verifies that the theme is a Composer package; if not, the command terminates.
  3. Checks for dependencies; if there are any, the command terminates.

    To work around this, you can either uninstall all themes at the same time or you can uninstall the depending theme first.

  4. Verifies that the theme is not being used; if it is being used, the command terminates.
  5. Verifies that the theme is not the base of the virtual theme; if it is the base of a virtual theme, the command terminates.
  6. Puts the store in maintenance mode.
  7. If --backup-code is specified, backs up the Magento 2 codebase, excluding the pub/static, pub/media, and var directories.

    The backup file name is var/backups/<timestamp>_filesystem.tgz

    You can restore backups at any time using the magento setup:rollback command.

  8. Removes themes from the theme database table.
  9. Remove themes from code base using composer remove.
  10. Cleans the cache.
  11. Cleans generated classes
  12. If --clear-static-content is specified, cleans generated static view files.

For example, if you attempt to uninstall a theme that another theme depends on, the following message displays:

Cannot uninstall frontend/ExampleCorp/SampleModuleTheme because the following package(s) depend on it:
    ExampleCorp/sample-module-theme-depend

One alternative is to uninstall both themes at the same time as follows after backing up the Magento codebase:

magento theme:uninstall frontend/ExampleCorp/SampleModuleTheme frontend/ExampleCorp/SampleModuleThemeDepend --backup-code

Messages similar to the following display:

Code backup is starting...
Code backup filename: 1435261098_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /var/www/html/magento2/var/backups/1435261098_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.Removing frontend/ExampleCorp/SampleModuleTheme, frontend/ExampleCorp/SampleModuleThemeDepend from database
Loading composer repositories with package information
Updating dependencies (including require-dev)
Removing frontend/ExampleCorp/SampleModuleTheme, frontend/ExampleCorp/SampleModuleThemeDepend from Magento codebase
  - Removing ExampleCorp/sample-module-theme-depend (dev-master)
Removing ExampleCorp/SampleThemeDepend
  - Removing ExampleCorp/sample-module-theme (dev-master)
Removing ExampleCorp/SampleTheme
Writing lock file
Generating autoload files
Cache cleared successfully.
Alert: Generated static view files were not cleared. You can clear them using the --clear-static-content option.
Failure to clear static view files might cause display issues in the Admin and storefront.
Disabling maintenance mode

To uninstall a Magento Admin theme, you must also remove it from your component's dependency injection configuration, <component root directory>/etc/di.xml.