1、在安装ninja的过程中需要先安装re2c(github地址:https://github.com/skvadrik/re2c):
            
            
              bash
              
              
            
          
          git clone https://github.com/skvadrik/re2c.git
        (也可直接下载最新的release压缩包,并解压。下载地址:https://github.com/skvadrik/re2c/releases)
打开终端,cd到re2c目录下执行:
            
            
              bash
              
              
            
          
          ./autogen.sh
        这一步若报错:autoreconf: command not found,说明未安装automake,执行第2步安装automark;若执行成功直接执行第3步
2、通过homebrew安装automake,若未安装homebrew,先执行以下命令安装homebrew:
            
            
              bash
              
              
            
          
          /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
        已安装homebrew,安装automake:
            
            
              bash
              
              
            
          
          brew install automake
        安装libtool
            
            
              bash
              
              
            
          
          brew install libtool
        以上步骤完成之后,接着执行第1步
3、接着执行:
            
            
              bash
              
              
            
          
          $ ./configure 
$ make -j4 && make install
        4、以上3步之后,rec2就安装完成了,接下来安装ninja,执行以下命令:
            
            
              bash
              
              
            
          
          git clone https://github.com/ninja-build/ninja.git && cd ninja
        Python安装:
            
            
              bash
              
              
            
          
          ./configure.py --bootstrap
        CMake安装:
            
            
              bash
              
              
            
          
          cmake -Bbuild-cmake -H.
cmake --build build-cmake
        最后,将可执行文件拷贝到/usr/bin/(或/usr/local/bin)目录下:
            
            
              bash
              
              
            
          
          cp ninja /usr/bin/   #使用sudo不能复制到/usr/bin/目录下,可使用下面的方法
或
ln -s /Users/mac/code/ninja/ninja /usr/local/bin/ninja
        注:在/.zshrc或/.bash_profile文件中,设置alias=/Users/mac/code/ninja/ninja,没起作用。