How to install Material UI v5

Materia UI is an open-source React UI library released in 2014. It consists of predefined components that can easily be used in the React applications. The library implements Google’s Material Design. Material UI components are self-supporting and only inject the styles they need to display. The version 5 for Material UI was released in 2021. In this Answer, we will see how we can install Material UI v5 in the React application.

Installation

To use Material UI in the React application, we need to run one of the following commands in the React project directory's terminal:

Using npm:
npm install @mui/material @emotion/react @emotion/styled
Using yarn:
yarn add @mui/material @emotion/react @emotion/styled
Commands to install Material UI in React application

Further, we need to install Material UI icons in the React app. We can run the following commands to do so.

Using npm:
npm install @mui/icons-material
Using yarn:
yarn add @mui/icons-material
Commands to install Material UI icons

Material UI uses Roboto font for its texts. Therefore, we can run the following command to install the font.

Using npm:
npm install @fontsource/roboto
Using yarn:
yarn add @fontsource/roboto
Commands to install Roboto font

Commands execution

In the terminal below, a React application is configured. We can run the following commands and install Material UI.

  1. npm install @mui/material @emotion/react @emotion/styled

  2. npm install @mui/icons-material

  3. npm install @fontsource/roboto

  4. To confirm that all dependencies for Material UI have been installed, we can check the package.json file and see that the dependencies are added under the dependencies section. Run the cat package.json command in the terminal to view the contents.

Terminal 1
Terminal
Loading...

After running the above commands, we can now use the components provided by the Material UI.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved