在linux Debian里安装golang(https://golang.google.cn/doc/install):
Download the archive and extract it into /usr/local
, creating a Go tree in /usr/local/go
. For example:
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz
(Typically these commands must be run as root or through sudo
.)
Add /usr/local/go/bin
to the PATH
environment variable. You can do this by adding this line to your /etc/profile
(for a system-wide installation) or $HOME/.profile
:
export PATH=$PATH:/usr/local/go/bin
Note: changes made to a profile
file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile
.
照着命令打的,然后在shell里输入go,就是没有反应,提示bash: go: command not found;
感觉path没设对,改改重启都一样不行,每次都要在终端里先输入“source /etc/profile”;重新打开一个终端需要重新输人,root
和普通用户一样,都找不到命令;/etc/profile内容
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
PATH="/usr/local/go/bin:/opt/clion-2019.1.4/bin":$PATH
export PATH
搜索发现是shell的问题;
/etc/profile是作为login shell才被读取的配置文件。
非login shell只看bashrc。
在终端模拟器的首选项中“一般”选项卡下有一个“作为登录Shell运行命令”的选项,默认是不选中的,选择上就解决了。
具体流程参见man bash(INVOCATION部分)https://bbs.csdn.net/topics/391032579
-!!-login shell与non-login shell的区别
Bash应该是我们每天日常工作接触最多的东西了,就像我们最忠实的朋友,我们有必要了解一下这位朋友的“习性”。
Bash有几种不同的运行模式,login shell与non-login shell,interactive shell与non-interactive shell(比如执行shell脚本)。这两种分类方法是交叉的,也就是说一个login shell可能是一个interactive shell,也可能是个non-interactive shell。
在下列情况下,我们可以获得一个login shell:
- 登录系统时获得的顶层shell,无论是通过本地终端登录,还是通过网络ssh登录。这种情况下获得的login shell是一个交互式shell。
- 在终端下使用--login选项调用bash,可以获得一个交互式login shell。
- 在脚本中使用--login选项调用bash(比如在shell脚本第一行做如下指定:#!/bin/bash --login),此时得到一个非交互式的login shell。
- 使用"su -"切换到指定用户时,获得此用户的login shell。如果不使用"-",则获得non-login shell。
login shell与non-login shell的主要区别在于它们启动时会读取不同的配置文件,从而导致环境不一样。login shell启动时首先读取/etc/profile全局配置,然后依次查找~/.bash_profile、~/.bash_login、~/.profile三个配置文件,并且读取第一个找到的并且可读的文件。login shell退出时读取并执行~/.bash_logout中的命令。
交互式的non-login shell启动时读取~/.bashrc资源文件。非交互式的non-login shell不读取上述所有配置文件,而是查找环境变量BASH_ENV,读取并执行BASH_ENV指向的文件中的命令。
如果使用命令"sh"调用bash,bash会尽可能保持向后兼容。作为login shell启动时,bash依次读取/etc/profile和~/.profile配置文件。作为non-login shell启动时,bash读取环境变量ENV指向的文件。
通常我们要定制一些配置时,将配置写在~/.bashrc中,然后在~/.bash_profile中读取~/.bashrc,这样可以保证login shell和交互式non-login shell得到相同的配置。至于/etc/profile就不要轻易去改啦,毕竟会影响系统全局的配置。