linux普通用户编译,linux非root用户下安装软件,搭建生产环境

之前的用实验室的服务器,因为某些原因,使用的用户没有root权限。linux的非root用户很多软件无法安装,非常的不方便。我的方法是使用brew来代替系统的包管理工具。brew是最先用在mac上的包管理工具,可以将所有的包托管在user本地的环境内。下面的文档中运行的时候记得将用户名改成自己的。

1. 安装anaconda

下载官方anaconda python安装包(minicondo也行),将conda加入~/.bashrc的系统变量中(在安装中会提示你运行 conda init,点yes就会直接复制到~/.bashrc中了)。这一步的目的是去安装curl, curl是下载安装brew必备的工具,此时curl会安装在/home/username/anaconda3/bin中

conda install curl --use-local

建议这里装完再装一个vim,方便文本编辑

2. 安装brew

使用curl命令下载安装brew,中间有一些错误不用管他,结束后输入brew有返回就说明安装成功

sh -c "$(curl -fssl https://raw.githubusercontent.com/linuxbrew/install/master/install.sh)"

之后将一下brew加入~/.bashrc中

export homebrew_prefix="/home/username/.linuxbrew";

export homebrew_cellar="/home/username/.linuxbrew/cellar";

export homebrew_repository="/home/username/.linuxbrew/homebrew";

export path="/home/username/.linuxbrew/bin:/home/username/.linuxbrew/sbin:$path";

export manpath="/home/username/.linuxbrew/share/man:$manpath";

export infopath="/home/username/.linuxbrew/share/info:$infopath";

此时保证brew已经是一个可以在终端被调用, 接下来是关键的一步

在/home/username/.linuxbrew/homebrew/library/homebrew/brew.sh#l200上进行加上一行

if [[ -n "$homebrew_force_brewed_curl" &&

-x "$homebrew_prefix/opt/curl/bin/curl" ]] &&

"$homebrew_prefix/opt/curl/bin/curl" --version >/dev/null

then

homebrew_curl="$homebrew_prefix/opt/curl/bin/curl"

elif [[ -n "$homebrew_developer" && -x "$homebrew_curl_path" ]]

then

homebrew_curl="$homebrew_curl_path"

else

homebrew_curl="curl"

fi

homebrew_curl="/home/username/anaconda/bin/curl" # 加上这一行!

然后输入 brew install curl

装完之后brew.sh会自动抹去自己之前的修改 : ),然后brew就正式能用了

比如 brew install tmux, brew install htop,只有brew有的包都可以装(参考包列表)

3. 手动编译安装软件包

如果brew里面没有某个包,需要自己编译的话,一般的linux软件包都是make编译的,一般修改下configure然后再make && make install 就好了,如下三行命令:

./configure --prefix=/home/username/.local

make

make install

# 如果要卸载 运行 make uninstall

最后分享下我的~/.bashrc ,其中 ~/.local/bin 和 ~/.local/lib加到path里面是为了自己编译安装用的。

export path=~/.local/bin:$path

export c_include_path=$c_include_path:~/.local/include

export cplus_include_path=$cplus_include_path:~/.local/include

export ld_library_path=~/.local/lib:$ld_library_path

# >>> conda initialize >>>

# !! contents within this block are managed by 'conda init' !!

__conda_setup="$('/home/username/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"

if [ $? -eq 0 ]; then

eval "$__conda_setup"

else

if [ -f "/home/username/anaconda3/etc/profile.d/conda.sh" ]; then

. "/home/username/anaconda3/etc/profile.d/conda.sh"

else

export path="/home/username/anaconda3/bin:$path"

fi

fi

unset __conda_setup

# <<< conda initialize <<<

export homebrew_prefix="/home/username/.linuxbrew";

export homebrew_cellar="/home/username/.linuxbrew/cellar";

export homebrew_repository="/home/username/.linuxbrew/homebrew";

export path="/home/username/.linuxbrew/bin:/home/username/.linuxbrew/sbin:$path";

export manpath="/home/username/.linuxbrew/share/man:$manpath";

export infopath="/home/username/.linuxbrew/share/info:$infopath";

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值