Mac OS X 유틸리티를 GNU 핵심 유틸리티로 바꾸는 방법은 무엇입니까? 차이점이 있음을

Mac OSX와 Linux에서 사용한 유틸리티 명령간에 약간의 차이점이 있음을 발견했습니다. 내 경험을 통일시키고 싶다.

모든 mac 유틸리티를 GNU 유틸리티로 바꾸려면 어떻게해야합니까?



답변

이것은 g 접두사가있는 GNU 유틸리티에 대한 심볼릭 링크를 다음에 추가합니다 /usr/local/bin/.

brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep

brew search gnu다른 패키지를 참조하십시오 . g 접두사없이 명령을 사용하려면 예를 들어 /usr/local/opt/coreutils/libexec/gnubin에서 다른 디렉토리 앞에 추가 하십시오 PATH.

$ brew info coreutils
coreutils: stable 8.21
http://www.gnu.org/software/coreutils
Depends on: xz
/usr/local/Cellar/coreutils/8.20 (208 files, 9.4M)
/usr/local/Cellar/coreutils/8.21 (210 files, 9.6M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/coreutils.rb
==> Caveats
All commands have been installed with the prefix 'g'.

If you really need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:

    PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:

    MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"


답변

게다가 brew install coreutils, 당신은 또한 다음과 같은 몇 가지 다른 패키지를 설치해야 할 수도 있습니다 gnu-sed, grep:

brew install findutils
brew install gnu-indent
brew install gnu-sed
brew install gnutls
brew install grep
brew install gnu-tar
brew install gawk

--with-default-names옵션은 2019 년 1 월부터 제거 되므로 g접두사 없이 사용하려면 각 바이너리를 경로에 추가해야합니다 .

이전 참조 ( --with-default-names사용 가능한 경우) : http://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/


답변

교체를 권장 지 모르겠습니다 . 그러나 다른 경로에 설치하여 그런 식으로 활용할 수 있습니다. 전반적으로 Linux에서 왔으며 더 많은 “일반적인”* nix 유틸리티 및 apt와 유사한 시스템에 액세스하려면 Macports를 참조하십시오 .
http://www.macports.org

예를 들어, 애플에 포함 된 GCC와는 반대로 최신 “일반”GCC를 예로 사용할 수 있습니다.


답변

나는 이것을 정확하게하기 위해 스크립트를 작성했습니다! 스크립트는 여기 (또는 아래)에서 볼 수 있습니다 . 그러나이 게시물이 이전에 링크 된 최신 버전의 스크립트를 반영한다고 항상 보장 할 수는 없습니다.

스크립트를 실행하면 Homebrew가 설치되고 (아직 설치되지 않은 경우) 관련된 모든 GNU 유틸리티가 설치되고 (아직 설치되지 않은 경우) PATH설치된 유틸리티에서 변수가 작성됩니다.

#!/bin/bash

# Install Homebrew (if not already installed)
ruby -e "$(curl -fsSL "\
"https://raw.githubusercontent.com/Homebrew/install/master/install)"

# Install required packages from Homebrew
brew tap homebrew/dupes
brew install coreutils binutils diffutils ed findutils gawk gnu-indent gnu-sed \
  gnu-tar gnu-which gnutls grep gzip screen watch wdiff wget bash gdb gpatch \
  m4 make nano file-formula git less openssh python rsync svn unzip vim \
  --default-names --with-default-names --with-gettext --override-system-vi \
  --override-system-vim --custom-system-icons

# Empty the .bash_path file that holds GNU paths
> ~/.bash_path

# Build PATH variable script in ~/.bash_path
for i in /usr/local/Cellar/*/*/bin; do
  echo 'export PATH="'$i':$PATH"' >> ~/.bash_path
done
for i in /usr/local/Cellar/*/*/libexec/gnubin; do
  echo 'export PATH="'$i':$PATH"' >> ~/.bash_path
done
for i in /usr/local/Cellar/*/*/share/man; do
  echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path
done
for i in /usr/local/Cellar/*/*/libexec/gnuman; do
  echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path
done

# Check if .bash_path is being called from .bash_profile
PATCH=`grep "~/.bash_path" ~/.bash_profile`
if [ "$PATCH" == "" ]; then
  # Add Ubuntu-style PS1 to .bash_profile
  cat <<EOF > ~/.bash_profile
export PS1="\[\033[1;32m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]# "
EOF
  # Add .bash_path to .bash_profile
  echo "source ~/.bash_path" >> ~/.bash_profile
fi


답변

macOS CLI를 새로운 GNU / Linux CLI 환경으로 투명하게 변환하는 스크립트를 작성했습니다.

  • 누락 된 GNU 프로그램 설치
  • 오래된 GNU 프로그램 업데이트
  • 사전 설치된 BSD 프로그램을 선호하는 GNU 구현으로 교체
  • 널리 사용되는 GNU / Linux 배포판에서 공통적 인 다른 프로그램 설치

https://github.com/fabiomaia/linuxify

git clone https://github.com/fabiomaia/linuxify.git
cd linuxify/
./linuxify install

또한 모든 것을 쉽게 취소 할 수 있습니다.

./linuxify uninstall


답변