如何永久启用 scl CentOS 6.4?

th3*_*0id 46 linux command-line bash command scl

我安装了较新版本的 devtoolset (1.1),并想知道如何将这些永久设置为默认值。现在,当我通过 ssh 进入运行 CentOS 的服务器时,我必须运行此命令scl enable devtoolset-1.1 bash

我尝试将它添加到 ~/.bashrc 并简单地将其粘贴到最后一行,但没有成功。

Des*_*ica 83

在您的~/.bashrc~/.bash_profileSimply 源中,使用devtoolset 提供的“启用”脚本。例如,使用 Devtoolset 2,命令是:

source /opt/rh/devtoolset-2/enable
Run Code Online (Sandbox Code Playgroud)

或者

source scl_source enable devtoolset-2
Run Code Online (Sandbox Code Playgroud)

效率更高:没有叉形炸弹,没有棘手的外壳

  • 获取此文件仍然可以与 devtoolset-7 一起使用 (2认同)

oHo*_*oHo 14

一个替代方案source /opt/rh/devtoolset-4/enable

source scl_source enable devtoolset-4
Run Code Online (Sandbox Code Playgroud)

上面的 shell 脚本scl_source比使用硬编码路径更优雅(在另一台机器上可能会有所不同)。然而scl_source,因为/opt/rh/devtoolset-4/enable用途scl_source和其他东西而减少。

要使用scl_source您可能需要升级包scl-utils

yum update scl-utils  # old scl-utils versions miss scl_source
Run Code Online (Sandbox Code Playgroud)

快速复制粘贴

echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
    # Do not forget to change the version ?
Run Code Online (Sandbox Code Playgroud)

好奇的人的源代码

scl_source源代码示例:https :
//gist.github.com/bkabrda/6435016

scl_source在我的Red Hat 7.1安装

#!/bin/bash

_scl_source_help="Usage: source scl_source <action> [<collection> ...]

Don't use this script outside of SCL scriptlets!

Options:
    -h, --help    display this help and exit"

if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
    echo "$_scl_source_help"
    return 0
fi


if [ -z "$_recursion" ]; then
    _recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
    # The only allowed action in the case of recursion is the same
    # as was the original
    _scl_scriptlet_name=$1
fi
shift 1

if [ -z "$_scl_dir" ]; then
    # No need to re-define the directory twice
    _scl_dir=/etc/scl/conf
    if [ ! -e $_scl_dir ]; then
        _scl_dir=/etc/scl/prefixes
    fi
fi

for arg in "$@"; do
    _scl_prefix_file=$_scl_dir/$arg
    _scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
    if [ $? -ne 0 ]; then
        echo "Can't read $_scl_prefix_file, $arg is probably not installed."
        return 1
    fi

    # First check if the collection is already in the list
    # of collections to be enabled
    for scl in ${_scls[@]}; do
        if [ $arg == $scl ]; then
            continue 2
        fi
    done

    # Now check if the collection isn't already enabled
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then
        _scls+=($arg)
        _scl_prefixes+=($_scl_prefix)
    fi;
done

if [ $_recursion == "false" ]; then
    _i=0
    _recursion="true"
    while [ $_i -lt ${#_scls[@]} ]; do
        _scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
        source "$_scl_scriptlet_path"
        if [ $? -ne 0 ]; then
            echo "Can't source $_scl_scriptlet_name, skipping."
        else
            export X_SCLS="${_scls[$_i]} $X_SCLS"
        fi;
        _i=$(($_i+1))
    done
    _scls=()
    _scl_prefixes=()
    _scl_scriptlet_name=""
    _recursion="false"
fi
Run Code Online (Sandbox Code Playgroud)


小智 5

问题是scl enable devtoolset-1.1 bash创建了一个新的 bash shell。所以当你把它放在你的 .bashrc 中时,它会创建一个新的 shell...它加载你的 .bashrc,它运行scl enable devtoolset-1.1 bash,它创建一个新的 shell,它加载你的 .bashrc... Forkbomb!

你可能想要在你的 .bashrc 中这样的东西:

if [ "$(gcc -dumpversion)" != "4.7.2" ]; then 
  scl enable devtoolset-1.1 bash
fi
Run Code Online (Sandbox Code Playgroud)

或者

if [ -z "$TRIEDSCLDEVTOOLSET" ]; then
  export TRIEDSCLDEVTOOLSET=true
  scl enable devtoolset-1.1 bash
fi
Run Code Online (Sandbox Code Playgroud)
  • 如果 devtoolset-1.1 不包含 gcc 4.7.2,第一个将继续 forkbomb,如果您的本机环境有 gcc 4.7.2,它也将无法工作。
  • 这将创建一个新的外壳,如上所述。因此,当您创建终端窗口或 ssh 会话时,您将处于两个 bash 会话中,并且必须exit两次。