linux 添加 系统路径

来源:互联网 发布:linux强制停止sh 编辑:程序博客网 时间:2024/05/22 05:21

到现在为止,切换到linux下有小半年儿了,离熟练运用还有一大段距离;成长缓慢的原因不是没遇到足够多的问题,而是遇到了问题却没能及时的记录,及时的复习,当然也没能够深入的举一反三的思考。经常觉得问题很简单,不值得记录;事实上linux也不是很复杂,高深之处就在于他的旁杂灵活,跟英语一样知识点颇多;而一旦掌握了非常多的小知识点后,驾轻就熟也就水到渠成了。

作为新手,经常遇到安装完新程序之后,每次都要敲入大段的路径去执行命令的苦恼。例如,我安装完redis之后,如果要进入客户端就得每次敲入/opt/redis/src/redis-cli,很麻烦。解决这个问题的方法(治标不治本,对于系统路径的理解,稍后去学习)就是将命令所在的路径加入到系统路径中去。

进入/etc,编辑profile(记得备份,以免失败)。

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).if [ "$PS1" ]; then  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then    # The file bash.bashrc already sets the default PS1.    # PS1='\h:\w\$ '    if [ -f /etc/bash.bashrc ]; then      . /etc/bash.bashrc    fi  else    if [ "`id -u`" -eq 0 ]; then      PS1='# '    else      PS1='$ '    fi  fifi# The default umask is now handled by pam_umask.# See pam_umask(8) and /etc/login.defs.if [ -d /etc/profile.d ]; then  for i in /etc/profile.d/*.sh; do    if [ -r $i ]; then      . $i    fi  done  unset ifiREDIS_HOME="/opt/redis-2.6.10/src"PATH="$PATH:$REDIS_HOME"  export PATH

按照粗体斜线部分添加即可。重启机器之后,可以看到已经生效。

echo "$PATH",看到REDIS_HOME已经加入。

但是在命令行里export PATH="new path"的方式,重启之后会失效(原因还未知)



原创粉丝点击