Choosing between multiple executables with same name in Linux

被刻印的时光 ゝ 提交于 2019-12-20 09:28:42

问题


The system I am using has gnuplot installed in /usr/bin. I don't have root, but I needed a newer version of gnuplot, so I installed it to $HOME/usr/bin.

I added $HOME/usr/bin to my path, but it still executes the one in /usr/bin if I just use the gnuplot command. I'd rather not have to specify $HOME/usr/bin/gnuplot every time I have to use it.

How do I tell Linux to use the one in my home directory, and not the one in /usr/bin?


回答1:


Executables are found in PATH order. You need to prepend ${HOME}/usr/bin to your path, like so:

export PATH="${HOME}/usr/bin:$PATH"



回答2:


Executables are found in PATH order. Your PATH apparently is set up such that /usr/bin precedes ~/usr/bin/.




回答3:


Besides modifying the PATH as has been explained, you can also use aliases like this (in BASH)

alias gn=$HOME/usr/bin/gnuplot

then you just run it with

gn



回答4:


What Bombe says is ok. I would add that you should declare your user specific PATH entries inside your user's bashrc ($HOME/.bashrc), so your PATH settings only apply to your user.



来源:https://stackoverflow.com/questions/413493/choosing-between-multiple-executables-with-same-name-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!