Ubuntu: How to link a binary

谁都会走 提交于 2019-12-04 11:18:29

问题


I have a C++ code. I compiled it and I now have the binary xyz. Now everytime I need to execute the binary, I had to switch to the corresponding directory to execute it using ./xyz But how do I run the binary using a command say xyz from anywhere. How do I link this binary to a command in ubuntu. I currently use Ubuntu 10.10


回答1:


Ubuntu sets your PATH environment variable to include ~/bin. So the easiest way to make xyz executable from anywhere is move xyz to ~/bin, or to make a symlink from ~/bin to the xyz's directory:

ln -s /path/to/xyz/directory/ ~/bin

Or, you could add /path/to/xyz/directory/ to your PATH environment variable.




回答2:


The problem is that Ubuntu doesn't know where to look for binary xyz.

You need to either add a path to your shell profile (it'll tell your shell where to look for programs like xyz) or add xyz to a directory that's already included in your path.

For example, /usr/bin is one place where binaries are stored normally. However, I'm not entirely sure what the generally accepted place to install new binaries is (/usr/bin might be generally reserved for system binaries).

Ubuntu by default uses a bash shell. In your home directory (~), you can check/edit your .profile file and either edit or see what directories are added to your PATH variable.



来源:https://stackoverflow.com/questions/4608496/ubuntu-how-to-link-a-binary

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