[mu@vm-cnt8:~/code/miniob]$ sudo bash build.sh init build.sh init HEAD is now at 5df3037d Merge branch 'release-2.1.12-stable-pull' into patches-2.1 build.sh: line 83: cmake: command not found build.sh: line 91: cmake: command not found build.sh: line 99: cmake: command not found build.sh: line 107: cmake: command not found
[mu@vm-cnt8:~/code/miniob]$ gcc --version gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the sourcefor copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[mu@vm-cnt8:~/code/miniob]$ cmake --version cmake version 3.27.4
CMake suite maintained and supported by Kitware (kitware.com/cmake). [mu@vm-cnt8:~/code/miniob]$ flex --version flex 2.6.1 [mu@vm-cnt8:~/code/miniob]$ bison --version bison (GNU Bison) 3.8 Written by Robert Corbett and Richard Stallman.
Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the sourcefor copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
在root中,也可以正常执行这些命令
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@vm-cnt8:~]# cmake --version cmake version 3.27.4
CMake suite maintained and supported by Kitware (kitware.com/cmake). [root@vm-cnt8:~]# flex --version flex 2.6.1 [root@vm-cnt8:~]# bison --version bison (GNU Bison) 3.8 Written by Robert Corbett and Richard Stallman.
Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
但是sudo执行miniob的安装脚本的时候,却找不到cmake命令
2.debug过程
经过大佬的教学,知道了一个新的sudo用法:sudo -E
sudo -E 是继承当前用户的环境变量运行sudo后面的命令,否则环境变量会被清理掉;
但是在初次使用的时候,依旧无法成功编译miniob,也找不到cmake命令
1 2 3 4 5 6 7 8 9 10 11 12
[mu@vm-cnt8:~/code/miniob]$ sudo -E bash build.sh init [sudo] password for mu: build.sh init HEAD is now at 5df3037d Merge branch 'release-2.1.12-stable-pull' into patches-2.1 build.sh: line 83: cmake: command not found build.sh: line 91: cmake: command not found build.sh: line 99: cmake: command not found build.sh: line 107: cmake: command not found
[mu@vm-cnt8:~]$ sudo -E cmake --version [sudo] password for mu: sudo: cmake: command not found
3.最终解决:PATH环境变量
最终的解决办法是我自己想出来的(大佬也回复了我这个解决方案)
当前在子用户使用 sudo -E是找不到cmake命令的。
1 2 3
[mu@vm-cnt8:~]$ sudo -E cmake --version [sudo] password for mu: sudo: cmake: command not found