Linux tools on mac

Is it possible to install Linux packages on OS X?

I know that the Mac commandline is very similar to that of Linux operating systems, so it would be nice to use some features of Linux in my Mac, specially installing Linux packages. For example, in Linux we can install a package by simply typing sudo apt-get install «package name» at the prompt. Is it possible to do something like this on Mac?

3 Answers 3

Yes, it is possible to install and run a variety of UNIX applications on OS X. There are a few solutions out there, my choice and recommendation is Homebrew. I’ve found other solutions to be overly complex and unwieldy.

in linux terminal installing command does any thing automatically it downloads files and . how about Homebrew? is it required to download files manually?

@peaceman once you’ve set up Homebrew, it downloads all the dependencies and files you need for any package you install from its repository. It’s a beautiful thing, really.

@CajunLuke for one MacPorts will install duplicates of everything it needs. Don’t want another bzip2? Too bad, you’re getting one. Brew on the other hand leverages the existing system. I have 23 packages I like to install. With Macports that balloons with dependancies to 144 packages. With Homebrew, only 44. That’s what I call «overly complex». You should seriously try Homebrew. You’ll like it better.

Like I said, you should seriously try it. It’s easier to manage, it’s easier to use, it’s easier to fix and it’s easier to contribute. I’m not trying to win. Just see for yourself, then pick the one you prefer.

Источник

Install and Use GNU Command Line Tools on macOS/OS X

If you are moving onto macOS/OS X from GNU/Linux, you would probably find out that the command line tools shipped with OS X are not as powerful and easy to use as the tools in Linux. The reason is that macOS/Mac OS X uses the BSD version command line tools, which are different from the Linux version, while they are both compliant with POSIX standards. But we can easily install the GNU command line tools by using Homebrew in Mac OS X and set them as default.

Читайте также:  Use perl in linux

Note: you need to notice that you may have some compatibility issues with shell scripts written specifically for OS X after you have replaced your OS X commands with the GNU version. Although the very vast majority of shell scripts have no problem, you just need to be aware that when there comes a problem, this may be the spot to check on.

Install Homebrew

First, visit Homebrew homepage and follow the installation instructions to install Homebrew.

Shortcut: install the latest XCode and then run the following command to install:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then add the following line to your .bashrc or .zshrc:

export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"

Install the GNU Command Line Tools

(All the brew install commands below have been put into one script on GitHub for downloads.)
First comes the most important one — GNU Coreutils:

GNU Coreutils contains the most essential UNIX commands, such as ls, cat.

Then you may probably want to install the following ones (For some of the packages, you need to run brew tap homebrew/dupes first, but only once for your system):

brew install binutils brew install diffutils brew install ed --with-default-names brew install findutils --with-default-names brew install gawk brew install gnu-indent --with-default-names brew install gnu-sed --with-default-names brew install gnu-tar --with-default-names brew install gnu-which --with-default-names brew install gnutls brew install grep --with-default-names brew install gzip brew install screen brew install watch brew install wdiff --with-gettext brew install wget

The —default-names option will prevent Homebrew from prepending a g to each of the newly installed commands, thus we could use these commands as default commands over the ones shipped by OS X.

Читайте также:  List acl in linux

In addition, some GNU command line tools already exist by default on OS X, but you may want a newer version:

brew install bash brew install emacs brew install gdb # gdb requires further actions to make it work. See `brew info gdb`. brew install gpatch brew install less brew install m4 brew install make brew install nano

As a complementary set of packages, the following ones are not from GNU, but you can install and use a newer version instead of the version shipped by OS X:

brew install file-formula brew install git brew install openssh brew install perl brew install python brew install rsync brew install svn brew install unzip brew install vim --override-system-vi brew install macvim --override-system-vim --custom-system-icons brew install zsh

Now you should have an easier command line system in your OS X. Have fun with them!

Update 1: You may also want to add $HOMEBREW_PREFIX/opt/coreutils/libexec/gnuman to the MANPATH environmental variable, where $HOMEBREW_PREFIX is the prefix of Homebrew, which is /usr/local by default. (Thanks Matthew Walker!) Alternatively, there is also a one-line setup which you could put in your shell configuration files here by quickshiftin.

Update 2 All the brew install commands above have been put into one script on GitHub for downloads.

Источник

skyzyx / homebrew-gnubin.md

I think most of us realize that macOS isn’t a Linux OS, but what that also means is that instead of shipping with the GNU flavor of command line tools, it ships with the FreeBSD flavor. As such, writing shell scripts which can work across both platforms can sometimes be challenging.

Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with «g» by default.

All commands have been installed with the prefix «g». If you need to use these commands with their normal names, you can add a «gnubin» directory to your PATH from your bashrc.

Choosing GNU for Consistency

Читайте также:  Linux присвоить ip адрес

You can install most of the GNU flavored tools with:

brew install autoconf bash binutils coreutils diffutils ed findutils flex gawk \ gnu-indent gnu-sed gnu-tar gnu-which gpatch grep gzip less m4 make nano \ screen watch wdiff wget zip

Assuming you have a fairly standard Terminal/shell environment, and assuming that you want to use the GNU versions instead of the BSD versions for everything you’ve installed with Homebrew, you can append the following to your ~/.profile file.

UPDATE (2022-06-16): I now have an Intel MacBook Pro and an Apple Silicon Mac Studio. Homebrew moved with the new CPU architecture, so the following is what I now use that works across both machines (my shell profile is shared across machines with Dropbox and symlinks).

BREW_BIN="/usr/local/bin/brew" if [ -f "/opt/homebrew/bin/brew" ]; then BREW_BIN="/opt/homebrew/bin/brew" fi if type "$ " &> /dev/null; then export BREW_PREFIX="$("$ " --prefix)" for bindir in "$ /opt/"*"/libexec/gnubin"; do export PATH=$bindir:$PATH; done for bindir in "$ /opt/"*"/bin"; do export PATH=$bindir:$PATH; done for mandir in "$ /opt/"*"/libexec/gnuman"; do export MANPATH=$mandir:$MANPATH; done for mandir in "$ /opt/"*"/share/man/man1"; do export MANPATH=$mandir:$MANPATH; done fi

[ , b2sum , base32 , base64 , basename , basenc , cat , chcon , chgrp , chmod , chown , chroot , cksum , comm , cp , csplit , cut , date , dd , df , dir , dircolors , dirname , du , echo , env , expand , expr , factor , false , fmt , fold , groups , head , hostid , id , install , join , kill , link , ln , logname , ls , md5sum , mkdir , mkfifo , mknod , mktemp , mv , nice , nl , nohup , nproc , numfmt , od , paste , pathchk , pinky , pr , printenv , printf , ptx , pwd , readlink , realpath , rm , rmdir , runcon , seq , sha1sum , sha224sum , sha256sum , sha384sum , sha512sum , shred , shuf , sleep , sort , split , stat , stdbuf , stty , sum , sync , tac , tail , tee , test , timeout , touch , tr , true , truncate , tsort , tty , uname , unexpand , uniq , unlink , uptime , users , vdir , wc , who , whoami , yes

Источник

Оцените статью
Adblock
detector