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 <magento_root>/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:
- Updating the
parent
node information intheme.xml
to remove references to the theme. -
Removing theme code from the file system.
First steps
- 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:
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>
- To run Magento commands from any directory, add
<magento_root>/bin
to your systemPATH
.
Because shells have differing syntax, consult a reference like unix.stackexchange.com.
bash shell example for CentOS:
1
export PATH=$PATH:/var/www/html/magento2/bin
You can also 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’s docroot. Need help locating the docroot?
In addition to the command arguments discussed here, see Common arguments.
Uninstall themes
Command usage:
1
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 isfrontend/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:
- Verifies that the specified theme paths exist; if not, the command terminates.
- Verifies that the theme is a Composer package; if not, the command terminates.
-
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.
- Verifies that the theme is not being used; if it is being used, the command terminates.
- Verifies that the theme is not the base of the virtual theme; if it is the base of a virtual theme, the command terminates.
- Puts the store in maintenance mode.
-
If
--backup-code
is specified, backs up the Magento 2 codebase, excluding thepub/static
,pub/media
, andvar
directories.The backup file name is
var/backups/<timestamp>_filesystem.tgz
You can restore backups at any time using the magento setup:rollback command.
- Removes themes from the
theme
database table. - Remove themes from code base using
composer remove
. - Cleans the cache.
- Cleans generated classes
- 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:
1
2
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:
1
magento theme:uninstall frontend/ExampleCorp/SampleModuleTheme frontend/ExampleCorp/SampleModuleThemeDepend --backup-code
Messages similar to the following display:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
.