美文网首页
Linux修改PATH路径

Linux修改PATH路径

作者: SimonJoe246 | 来源:发表于2019-02-18 16:54 被阅读0次

    何为 PATH?

    PATH 路径是环境变量,和 Windows 系统类似,是可执行命令文件的存放路径。

    当你在命令行输入一个 ls 命令时,系统会在当前工作目录以及 PATH 的路径中依次寻找,找到的话执行,找不到的话返回 command not found: ls

    PATH 路径可以通过 echo $PATH 查看,

    或者 env|grep PATH

    修改 PATH

    添加

    • 临时添加 usr/local/bin

      直接在终端输入命令 PATH=$PATH:/usr/local/bin

      更改在当前会话有效,退出本次会话后则失效

    • 永久添加 usr/local/bin

      修改 .bashrc 文件

      添加一句:export PATH=$PATH:/usr/local/bin

    删除

    • 临时删除

      直接在终端输入命令 PATH=... ...为除去不想要的路径的其他所有路径

    • 永久删除

      • 将上面的临时命令放入 .bashrc 中:echo PATH=...
        或者在 .bashrc 文件末尾添加以下代码:
      ### remove unnecessary Win PATHs
      # This can prevent extension-less commands from bleeding into BASH.
      # (eg. "ng" would execute the Win bin if "@angular/cli" wasn't installed on Linux.)
      #
      function path_remove {
        # Delete path by parts so we can never accidentally remove sub paths
        PATH=${PATH//":$1:"/":"} # delete any instances in the middle
        PATH=${PATH/#"$1:"/} # delete any instance at the beginning
        PATH=${PATH/%":$1"/} # delete any instance in the at the end
      }
      
      path_remove '/mnt/c/Users/me/AppData/Roaming/npm'
      path_remove '/mnt/c/Users/me/AppData/Local/Yarn/bin'
      path_remove '/mnt/c/Program Files (x86)/Yarn/bin'
      path_remove '/mnt/c/Program Files/Git'
      path_remove '/mnt/c/Program Files/Git/cmd'
      path_remove '/mnt/c/Program Files/nodejs'
      path_remove '/mnt/c/OpenSSL-Win32/bin'
      path_remove '/mnt/c/Program Files (x86)/Python27'
      

    相关文章

      网友评论

          本文标题:Linux修改PATH路径

          本文链接:https://www.haomeiwen.com/subject/obzxhqtx.html