preface

As a loyal Windows user, I always felt that adding environment variables was very troublesome when I first connected to MAC. Recently, I encountered the same problem while building the Flutter development environment. So take some time to sort out how to set environment variables and view PATH on the MAC!

What’s the use of environment variables?

Let’s start by configuring the environment variables of flutter to illustrate the role of environment variables: 1. Enter the following command on the terminal

export PATH=`pwd`/flutter/bin:$PATH
Copy the code

2. Run the following command to check whether the flutter dependencies are installed

flutter doctor
Copy the code
  1. When you open a terminal and run the flutter doctor command again, the terminal will report an error: commend not found.

Q: What if we want terminals in any directory to execute flutter command statements?

Environment variables: in each directory of the operating system, you can access the contents of the required tool directory, which is equivalent to a shortcut for us to run scripts quickly.

Priority of environment variables in MAC

/etc/paths/system level: /etc/paths/system level: /etc/paths/system level: /etc/paths/system level: /etc/paths/system level: /etc/paths If // eg: ~/.bash_profile exists, the following files will be ignored. But ~/.bash_profile ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrcCopy the code

~/.bash_profile: This file contains bash shell information dedicated to the current user, which is read at login and each time a new shell is opened (each change requires a reboot to take effect)

The PATH of grammar

/ / use a comma to the export PATH = $PATH: < PATH1 > : < PATH2 > : < PATH3 > :... : < PATHN > / /, of course, also have to see someone is written so the export PATH = ${PATH} : < PATH1 > : < PATH2 > : < PATH3 > :... :<PATHN>Copy the code

Common Operation Commands

Create a file
touch ~/.bash_profile
Copy the code
Open the file
open ~/.bash_profile
Copy the code
Edit the file

Using the open command opens the.bash_profile file, so you can modify it directly and save it when you’re done.

Restart (to make the configuration file take effect)
source ~/.bash_profile
Copy the code
Check the PATH
echo $PATH
Copy the code

Write in the last

If there is a mistake, please leave a message, will be corrected in time! If feel helpful to you, please click a like or collect it!