如何为从源安装的程序创建终端命令
我最近尝试从源代码在 Ubuntu Natty 上安装 monit。这是我的代码:
apt-get -y install openssl libssl-dev bison flex
mkdir src && cd src
wget http://mmonit.com/monit/dist/monit-5.3.2.tar.gz
tar xzf monit-5.3.2.tar.gz
cd monit-5.3.2
./configure --prefix=/usr/local/monit
make && make install
但是,当我使用 apt-get 安装 Monit 时,我可以使用关键字 monit 直接从命令行调用 monit。当我从源代码安装时,我无法这样做。 PHP 也是如此。
当我从源代码安装 Monit(和其他 Linux 程序)时,如何启用此功能?
提前致谢。
编辑
我能够通过执行以下操作来解决此问题:
printf "\nPATH=/usr/local/monit/bin:\${PATH}\n" >> ~/.profile
source ~/.profile
这将适用于当前登录的用户(在我的情况下为 root)。要使其在系统范围内使用,只需将 ~/.profile
替换为 /etc/profile
即可。
所以现在我可以调用 monit
(以及我从源代码安装的任何其他程序)。
I recently tried to install monit on Ubuntu Natty from source. Here's my code:
apt-get -y install openssl libssl-dev bison flex
mkdir src && cd src
wget http://mmonit.com/monit/dist/monit-5.3.2.tar.gz
tar xzf monit-5.3.2.tar.gz
cd monit-5.3.2
./configure --prefix=/usr/local/monit
make && make install
However, when I install Monit using apt-get
I am able to call monit directly from the command line using the keyword monit
. I am not able to do so when I do the install from source. The same goes for PHP.
How can I enable this feature for when I install Monit (and other Linux programs) from source?
Thanks in advance.
EDIT
I was able to solve this by doing the following:
printf "\nPATH=/usr/local/monit/bin:\${PATH}\n" >> ~/.profile
source ~/.profile
This will apply for the currently logged in user (in my case root). To make it system-wide simply replace ~/.profile
with /etc/profile
.
So now I can can call monit
(and any other program I install from source).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用该命令安装它会将其放入 /usr/local/monit 中,而正如其他人所说,它不会位于您的 $PATH 中。不过,除了修改路径之外,还有多种选择。例如,您可以创建从实际可执行文件到路径中的可执行文件的符号链接。因此,如果可执行文件是 /usr/local/monit/monit,则可以
创建符号链接的优点是它适用于所有用户。
您还可以创建别名,但这仅适用于以您身份运行的应用程序。
Using that command to install it will put it in /usr/local/monit, which won't be in your $PATH, as others have said. There are several options besides modifying your path, though. For instance, you can create a symbolic link from the real executable to one in your path. So if the executable is /usr/local/monit/monit, you can
The advantage of creating the symbolic link is it will work for all users.
You can also create an alias, but that would only work for apps that run as you.
编辑
/etc/profile
以将路径/usr/local/monit
添加到PATH
变量。例如,如果你之前有过这个。
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
您可以将其更改为
PATH= “/usr/local/monit:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin”
Edit your
/etc/profile
to add the path/usr/local/monit
to thePATH
variable.For ex, if you earlier had this.
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
You could change it to
PATH="/usr/local/monit:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"