[问题]PATH设置,优先,相关文件删除

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
gugaotianshi
帖子: 63
注册时间: 2008-02-22 20:52

[问题]PATH设置,优先,相关文件删除

#1

帖子 gugaotianshi » 2008-02-24 16:05

我用Linux才不到一个月啊~~~
我用gnuplot的问题和这里一样
viewtopic.php?t=89587&sid=4f645ea1a67bb ... 8db1bfbc63

我的原因是以前自己编译过一个gnuplot。

现在问题来了。这两个gnuplot的路径是不一样的。
自己编译的,启动用的是 /usr/local/bin/gnuplot (这个没有X11)
而用源里的包安装的,启动用的是 /usr/bin/gnuplot

当我在终端输入gnuplot时,系统只会到 /usr/local/bin 里去找。
如果我把 /usr/local/bin/gnuplot 改名,比如 gnuplot_
系统就会提示找不到。(它也不会去 /usr/bin 找)

问题:
1 我怎么才能让系统到 /usr/bin 这个目录去找我要用的 gnuplot 启动?

2 我怎么才去掉 /usr/local/bin 这个PATH变量,我找不到 in
~/.profile
~/.bashrc
/etc/profile
/etc/bash.bashrc
它还会在哪里定义?

3 我以前编译的gnuplot,它生成的那些文件,我怎么找到,并删除?
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#2

帖子 xhy » 2008-02-24 17:39

1 卸载掉以前装的那个版本 或者修改PATH优先级 把/usr/bin放到最前面

2 这个环境变量最好不要去掉 想去掉就去
grep -R "/usr/local/bin" /etc 2>&-
grep -R "/usr/local/bin" $HOME 2>&-
这里会显示所有可能设置这个环境变量的配置文件

3 make install是安装 同样也会有make uninstall等卸载方式
如果没有 直接删除程序的文件就行了 ./configure的时候往往会配置目录
如果还没有 你就查看一下Makefile,看看他安装到哪些路径
目前负债150多万
gugaotianshi
帖子: 63
注册时间: 2008-02-22 20:52

#3

帖子 gugaotianshi » 2008-02-24 20:09

谢谢楼上的。我弄好了。
我是先下了gnuplot的源码包,然后参照里面的INSTALL手动把安装的文件删除了。(幸好文件不多= =)
然后重新编译,这次定制目录。然后再删除安装的文件,再从源里安装。
最后,重启。

不重启系统还是会在原来的/usr/local/bin 里去找,并提示找不到gnuplot。
我当时就郁闷,它怎么不遍历PATH。结果重启就可以了=。=
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#4

帖子 xhy » 2008-02-24 20:41

环境变量都在一个cache里
除了手工刷新cache以外 只能重启
目前负债150多万
zdp5528
帖子: 31
注册时间: 2008-02-02 18:28

#5

帖子 zdp5528 » 2008-02-25 8:36

存放环境变量的地方不是这个文件吗?/etc/enviments 我把环境变量都方在这里了,想怎么该就怎么该
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#6

帖子 aBiNg » 2008-02-25 9:19

/usr/bin/gnuplot
/usr/local/bin/gnuplot_
确认有以上两可执行文件,$PATH默认。

¶ which gnuplot
/usr/bin/gnuplot

shell如何会不去/usr/bin找gnuplot?
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#7

帖子 xhy » 2008-02-25 17:21

/usr/local/bin:/usr/bin:/bin:/opt/bin

前面的优先级高于后面的
目前负债150多万
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#8

帖子 aBiNg » 2008-02-25 19:16

xhy 写了:/usr/local/bin:/usr/bin:/bin:/opt/bin

前面的优先级高于后面的
gugaotianshi 写了:现在问题来了。这两个gnuplot的路径是不一样的。
自己编译的,启动用的是 /usr/local/bin/gnuplot (这个没有X11)
而用源里的包安装的,启动用的是 /usr/bin/gnuplot

当我在终端输入gnuplot时,系统只会到 /usr/local/bin 里去找。<-- 这一行是对的
如果我把 /usr/local/bin/gnuplot 改名,比如 gnuplot_
系统就会提示找不到。(它也不会去 /usr/bin 找)
系统就会提示找不到gnuplot么?不可能吧。

这与优先级有何关系呢?前面的优先,但找不到,当然会到后面的目录中找。只要存在,肯定可以找到。

aBiNg:~ ¶ which gnuplot gnuplot_
/usr/bin/gnuplot
/usr/local/bin/gnuplot_
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#9

帖子 xhy » 2008-02-25 22:59

你退出当前shell 重新登录一次shell 就又找到了

或者在当前shlle中运行一个新的shell
目前负债150多万
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#10

帖子 xhy » 2008-02-25 23:13

果然和我猜想的一样

代码: 全选

       If  the name is neither a shell function nor a builtin, and contains no slashes, bash searches each element of
       the PATH for a directory containing an executable file by that name.  Bash uses a hash table to  remember  the
       full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below).  A full search of the direc-
       tories in PATH is performed only if the command is not found in the hash table.  If the search  is  unsuccess-
       ful, the shell prints an error message and returns an exit status of 127.

       If the search is successful, or if the command name contains one or more slashes, the shell executes the named
       program in a separate execution environment.  Argument 0 is set to the name given, and the remaining arguments
       to the command are set to the arguments given, if any.
目前负债150多万
zdp5528
帖子: 31
注册时间: 2008-02-02 18:28

#11

帖子 zdp5528 » 2008-02-28 9:48

有个问题:/etc/enviorments不是专门修改PATH变量的地方吗?我做过实验,当我装jdk时配置环境变量,我在export 引入环境变量path后,还得该/etc/enviroment 中的环境变量path的值,两者要统一,否则java javac就有问题,那这个文件/etc/enviroments到底是什么作用呢?他设置的是全局环境变量???
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#12

帖子 xhy » 2008-02-28 11:17

saga@Gentoo ~ $ cat /etc/environment
#
# This file is parsed by pam_env module
#
# Syntax: simple "KEY=VAL" pairs on seperate lines
#
#
我的/etc/enviroment什么都不做

不同的发行版 有不同的办法设置环境变量
Gentoo是在/etc/env.d下配置
目前负债150多万
回复