Mac os how to update bash

How To Update macOS Using Command Line Software Update Tool

H ow do I install software updates from the command line tool on my Apple macOS / OS X computer? How can I remotely update my Apple computer by just sshing into a system? Is there is something like apt-get command or yum command for Apple macOS/OS X?

You need to use the softwareupdate command to checks for new and updated versions of your software based on information about your Apple Mac computer and current software. This command requires admin authentication for all commands i.e. you need to run it using sudo tool. In this tutorial you will learn how to install software updates from the bash command line on a macOS/OS X.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Apple macOS or OS X with Terminal application
Est. reading time 3 minutes

Procedure to update macOS using command

  1. Open the terminal application on your macOS (Applications > Utilities > Terminal)
  2. Check for macOS update using the
    softwareupdate -l
  3. Note down available updates names.
  4. Install new updates on macOS using the following command:
    sudo softwareupdate -i update_pkg_name

Let us see how to update macOS using a terminal command in details.

How do I find all available updates on macOS?

Open the terminal app and type the following commands. Type the following command:
softwareupdate -l
OR
softwareupdate —list
Sample outputs:

Fig.01: List all available updates

  1. RAWCameraUpdate6.17-6.17 is software available to update also know as the identifier.
  2. 6.17 is version number
  3. 7455k download size
  4. Please note that updates that need a restart are marked with [restart].

How do I install specified update?

To install update called ‘RAWCameraUpdate6.17-6.17’, enter:
sudo softwareupdate -i RAWCameraUpdate6.17-6.17
Sample outputs:

A note about dealing with update names with white spaces

Some update names may include spaces, enclose the update name using a single quote character as follows:
sudo softwareupdate -i ‘OS X El Capitan Update-10.11.1’

How do I see software download and update progress?

Pass the -v option as follows:
sudo softwareupdate -vi RAWCameraUpdate6.17-6.17
OR
sudo softwareupdate -v -i iTunesXPatch-12.3.1
Sample outputs:

How do I just download update but not install on my system?

Use the following syntax:
sudo softwareupdate -d nameHere
sudo softwareupdate -d iTunesXPatch-12.3.1
To cancel a download, enter:
sudo softwareupdate -e

All updates that are recommended for your system:
sudo softwareupdate -r

Updating Mac using the Terminal app

To install all updates that are applicable to your system, enter:
sudo softwareupdate -i -a
Install all but make sure you ignore ‘JavaForOSX’ updates:
sudo softwareupdate —ignore JavaForOSX
To clear the list ignored updates, enter:
sudo softwareupdate —reset-ignored

Turn on or off automatic background check

Turn on Automatic check:
sudo softwareupdate —schedule on
Automatic check is off:
sudo softwareupdate —schedule off
To see info on all options, type:
man softwareupdate
softwareupdate -h
Here is what I see:

Источник

Как обновить bash на Mac OS X Yosemite

просто пытаюсь немного научиться скриптингу bash.
Моя старая версия bash:

я обновил свой bash на mac os x yosemite с homebrew:

затем в свойствах терминала я изменил стандартный путь снаряда от /bin/bash to /usr/local/bin/bash (как я понимаю, именно здесь доморощенный устанавливает обновленный bash).

потом я снова проверил результат (и вроде бы все хорошо):

но когда я пытался написать простой bash-скрипт:

почему версия Bash меняется на старую, когда я пытаюсь выполнить скрипт в той же оболочке. Это просто выводит меня из себя! Пожалуйста кто-нибудь объясните мне в чем моя проблема)))

3 ответов

ваша проблема находится в первой строке. У вас есть это:

, в котором явно указано, что сценарий оболочки должен запускаться со старым /bin/bash . Что ты действительно хочу, это:

использовать новый bash С /usr/local/bin .

установить новый bash:

сделать это оболочкой по умолчанию:

установка окружения в скрипте:

используя env будет искать Баш в своем $PATH и использовать первый встречный. Вы можете увидеть, какой bash он будет использовать путем ввода which bash . Если он видит /bin/bash во-первых, вам нужно будет установить $PATH in

/.bashrc и /.bash_profile .

Как указал pjv, вы действительно должны использовать

в ваших скриптах везде будет переносимо. Е. Г. если вы пытаетесь запустить свой скрипт

он потерпит неудачу на большинстве систем linux.

Источник

Install Bash 5 on macOS

The default bash on macOS is still bash v3:

Just recently, bash v5 was released. The discrepancy comes from the fact that bash has been licensed as GPL v3 since version 4. Apple does not include GPL v3 licensed tools with macOS.

However, nothing is keeping you from downloading and installing the latest bash version.

New features include, among many other things, associated arrays (i.e. dictionaries) and better auto-completion setup.

While you would think this is a common desire, most pages I have found will simply point to Homebrew to download and install a newer bash version.

The main challenge with using brew is that it does not work on the scale that MacAdmins require. brew is designed for single user installation, where the user has administrator privileges. brew ’s workflows do not scale to large deployments controlled with a management system.

Ideally, there would be package installer for the latest bash version. Unfortunately, the bash project does not provide one.

In this post, I will show how you can install the latest bash version without brew and how to build an installer package for deployment.

Manual Installation

This requires Xcode or the Developer Command Line Tools to be installed.

First, download the source for the latest bash version from this page. As of this writing the latest version is bash-5.0 and the file you want is bash-5.0.tar.gz . Once downloaded, you can expand the archive in Finder by double-clicking.

Open a Terminal window and change directory to the newly expanded bash-5.0 directory. Then run the configure script there.

The configure process will take a while, there will be plenty of messages showing progress.

Once the configure process is complete. You can build bash with the make command.

This will build the bash binary and the supporting files in the current directory. That’s not where we want it in the end, but it is probably a good idea see if the build process works. This will (again) take a while. There will be some odd looking warnings, but you can ignore those.

When make succeeds, you can actually install bash v5 with

This will build and install the bash binary and supporting files in /usr/local/bin and /usr/local . sudo is required to modify /usr/local .

If you were just looking for a way to install bash v5 without brew , you are done!

There is more useful information in the rest of the post, though, so keep reading!

How the new and the old bash interact

By default, the bash v5 binary is called bash and will be installed in /usr/local/bin . The macOS default PATH lists /usr/local/bin before /bin where the default bash v3 binary, also called bash , is located.

This means, that when a user types bash in to a shell, the version in /usr/local/bin will be preferred over the pre-installed bash v3.

You can test this behavior in Terminal. Since the default shell has not yet been changed from /bin/bash the Terminal still opens to bash v3. You can test this by showing the BASH_VERSION environment variable:

But when you then run bash it will invoke /usr/local/bin/bash , so it will run the new bash v5. It will show this in the prompt, but you can also verify the BASH_VERSION .

This might be the setup you want, when you want to use bash v5 always. It might lead to some unexpected behavior for some users, though.

One option to avoid this ambiguity is to rename the binary in /usr/local/bin to bash5 . But then other tools such as env (mentioned below) will not find the binary any more.

Note: the PATH in other contexts will likely not contain /usr/local/bin and further confuse matters.

bash v5 and Scripting

Scripts using bash , should have the full path to the binary in the shebang. This way, the script author can control whether a script is executed by the default bash v3 ( /bin/bash ) or the newer bash v5 ( /usr/local/bin/bash or /usr/local/bin/bash5 ).

It is often recommended to use the env command in the shebang:

The env command will determine the path to the bash binary in the current environment. (i.e. using the current PATH ) This is useful when the script has to run in various environments where the location of the bash binary is unknown, in other words across multiple Unix and Unix-like platforms. However, this renders the actual version of bash that will interpret the script unpredictable.

For example, assume you have bash v5 installed in the default configuration (as /usr/local/bin/bash . A script with the shebang #!/usr/bin/env bash launched in the user environment (i.e. from Terminal) will use the newer bash , as /usr/local/bin comes before /bin in the search order.

When you launch the same script in a different context, e.g. as an installation script, an AppleScript, or a management system, /usr/local/bin will likely not be part of the PATH in that environment. Then the env shebang will choose /bin/bash (v3). The script will be interpreted and might behave differently.

Administrators prefer certainty in their managed environments. Administrators should know the location and versions of the binaries on their systems. For management scripts, you should avoid env and use the proper full path to the desired interpreter binary.

The solutions to resolve the ambiguity are

  • use the full path to the binary in the shebang
  • manage and update the additional custom version of bash with a management system
  • (optional) rename the newer bash binary to bash5 or bash4 (this also allows you to have bash v4 and bash v5 available on the same system)
  • Scripting OS X: On the Shebang
  • Scripting OS X: Setting the PATH in Scripts

Changing a user’s default Shell to bash v5

Even though we have installed bash v5, the default shell of a new Terminal window will still use the built-in bash v3.

The path to the default shell is stored in the user record. You can directly change the UserShell attribute with dscl , in the ‘Advanced Options’ of the ‘Users & Groups’ preference pane, or in Directory Utility.

There is also a command to set the default shell:

The chsh (change shell) command will check for allowed shells in the /etc/shells file. You can easily append a line with /usr/local/bin/bash to this file, and then chsh will work fine.

Note: if you choose to rename the bash binary, you have to use the changed name in /etc/shells and with chsh .

Remember that just running chsh will not change the shell in the current Terminal window. It is best to close the old Terminal window and open a new one to get the new shell.

Packaging bash v5 for mass deployment

While these steps to install and configure bash v5 on a single Mac are simple enough, they would not work well with a management system for hundreds or thousands of Macs. We want to wrap all the files that make install creates into a package installer payload.

The —help option of the configure script yields this useful information:

By default, make install’ will install all the files in /usr/local/bin , /usr/local/lib etc. You can specify an installation prefix other than /usr/local using –prefix , for instance –prefix=$HOME`.

When we run the configure script with the —prefix option it creates a folder suitable as a payload for a package installer. We can then use pkgbuild to build to create an installer pkg:

(Note: the —prefix argument requires an absolute path.)

Automate the package creation

So, we have our workflow for building an installer package to distribute and configure bash v5:

  • download the archive
  • extract the archive
  • run configure with the —prefix argument
  • run make install to create the files in a payload folder
  • optional: rename the resulting bash binary to bash5 to avoid conflicts
  • add a postinstall script that adds /usr/local/bin/bash[5] to /etc/shells if not yet present
  • build the installer with pkgbuild

This sounds like a workflow ripe for automation. You can get the script from this repository.

You can pass a different (valid) bash version number as an argument to the script, e.g. 4.4.18 . (I did not test anything significantly older.) The script does not autodetect the latest version and defaults to version 5.0 when no argument is given. When an update to bash v5 is published, you will have to modify the version line or run the script with an argument.

I have not (yet) figured out how to detect the latest version from the download web page. An autopkg recipe will have to wait for that. (If someone else wants to tackle that, please do!)

20 thoughts on “Install Bash 5 on macOS”

Greetings, just ran across your post, the latest version of bash can be found with this (on MacOS using curl, no wget by default). Here’s to hoping that all the tics, slashes, quotes, etc are faithfully reproduced in the command below:

Источник

Upgrading Bash on macOS

One thing that many macOS users don’t know is that they are using a completely outdated version of the Bash shell. However, it is highly recommended to use a newer version of Bash on macOS, because it enables you to use useful new features. This article explains how to do this.

Default Bash Version on macOS

To see how outdated the Bash version included in macOS is, execute the following command:

As you can see, this is GNU Bash version 3.2, which dates from 2007! This version of Bash is included in all versions of macOS, even the newest one.

The reason that Apple includes such an old version of Bash in its operating system has to do with licensing. Since version 4.0 (successor of 3.2), Bash uses the GNU General Public License v3 (GPLv3), which Apple does not (want to) support. You can find some discussions about this here and here. Version 3.2 of GNU Bash is the last version with GPLv2, which Apple accepts, and so it sticks with it.

This means that the entire world (e.g. Linux) proceeds with new versions of Bash, whereas macOS users are stuck with an old version from a decade ago. At the time of this writing, the newest version of GNU Bash is 5.0 (see here), which has been released in January 2019. In this article, I give instructions to upgrade the default shell of your system to the newest version of Bash.

Why Upgrading?

But why even bother with getting a newer version if Bash 3.2 works fine? The main reason, for me personally, is programmable completion. This is a feature that allows command-specific auto-completions in Bash. You probably use auto-completion for completing commands, filenames, and variables by starting to type and then hitting Tab to auto-complete the current word (or hitting Tab two times to get a list of all possible completions, if there is more than one). This is the default completion of Bash.

However, programmable completion goes much beyond that, because it allows command-specific completions that can depend on the context. Imagine, for example, typing cmd -[tab][tab] , and then seeing a list of all options that are applicable to this command. Or typing cmd host rm [tab][tab] and then seeing a list of all the “hosts” that are specified in some configuration file. Programmable completion allows to do that.

Programmable completion logic is defined (by the creators of commands) in completion specifications, typically in the form of completion scripts. These completion scripts have to be sourced in your shell to enable the completion functionality for a command.

The problem is that the programmable completion features of Bash have been extended since version 3.2, and most completion scripts use these new features. This means that these completion scripts don’t work on Bash 3.2, which means that you miss out from the completion functionalities of many commands, if you keep using the default macOS shell.

By upgrading to a newer version of Bash, you become able to use these completion scripts, which can be extremely useful. I wrote an entire article called Programmable Completion for Bash on macOS, which explains all you need to know to take full advantage of programmable completion on macOS after upgrading to a newer Bash version.

How To Upgrade?

To upgrade the default shell of your macOS system to the latest version of Bash, you have to do three things:

  1. Install the latest version of Bash
  2. “Whitelist” new Bash as a login shell
  3. Set new Bash as the default shell

Each step is extremely easy, as explained in the following.

Note: the following instructions don’t change the old version of Bash, but rather install a new version and set it as the default. The two versions will exist side by side on your system, but you can just ignore the old version from there on.

Install

I recommend to use Homebrew to install the latest version of Bash:

That’s it already!

To verify the installation, you can check that you now have two versions of Bash on your system:

The first one is the new version, and the second one is the old version:

Since the directory of the new version ( /usr/local/bin ) comes by default before the directory of the old version ( /bin ) in the PATH variable, the version used when you just type bash is the new one:

So far, so good. Now you have make this version the default.

Whitelist

UNIX includes a security feature that restricts the shells that can be used as login shells (i.e. the shell used after logging in to the system) to a list of “trusted” shells. These shells are listed in the /etc/shells file.

Since you want to use the newly installed Bash shell as the default shell, it must be able to act as a login shell. That means, you have to add it to the /etc/shells file. You can edit this file as the root user:

And add the /usr/local/bin/bash shell to its content, so that the file looks something like this:

That’s it for this step!

Set Default Shell

At this point, if you opened a new terminal window, you would still be using Bash 3.2. This is because /bin/bash is still set as the default shell. To change this to your new shell, execute the following command:

That’s it! The default shell for your current user is now set to the new version of Bash. If you close and reopen the terminal window, you should now be using the new version already. You can verify this as follows:

The chsh command changes the default shell only for the user who executes the command. If you want to change the default shell for other users too, you can repeat this command by assuming another user’s identity (e.g. with su ). Most importantly perhaps you might want to change the default shell for the root user, which you can do as follows:

In this way, if you use sudo su to open a shell as the root user, it will also use the new Bash version.

Important Notes

Usage in Scripts

As mentioned, you didn’t change the default version of Bash, but rather installed a new version and set it as the default. The two versions of Bash exist side by side on your system:

  • /bin/bash : old version
  • /usr/local/bin/bash : new version

In shell scripts, you often have a shebang line like in the following script:

It is important to note that this shebang line explicitly refers to the old version of Bash (since it specifies /bin/bash ). This means that if you run this script, it will be interpreted by the old version of Bash (you can see it in the output of the script, which will be something like 3.2.57(1)-release ).

For most cases, this is probably not a problem. But if you wanted your script to be explicitly interpreted by the new version of Bash, you could change the shebang line like this:

Now the output will be something like 5.0.0(1)-release . However, note that this solution is non-portable, which means, it is likely to not work on other systems. This is because, other systems are likely to not have a shell located at /usr/local/bin/bash (whereas /bin/bash is almost a standard).

To combine the best of both worlds, you can use the following shebang line:

This is a recommended format for a shebang line. It works by inspecting the PATH and using the first encountered bash executable as the interpreter for the script. If the directory of the new version is located before the directory of the old version in the PATH (which is the default), then the new version will be used, and the output of the script will be something like 5.0.0(1)-release .

Instead of dealing with both versions of Bash, couldn’t you just delete the old version and put the new version in its place? For example, by creating a symlink in /bin/bash that points to the new version, like the following?

In this way, even scripts with a #!/bin/bash would be interpreted by the new version of Bash, so why not doing this?

You can do this, but you have to circumvent a macOS security feature called System Integrity Protection (SIP) (Wikipedia). This feature forbids write access to certain directories for even the root user (that’s why it’s also called “rootless”). These directories are listed here and include /bin . That means that even as the root user, you cannot execute the above commands, because you are not allowed to delete anything from or create any files in /bin .

The way around this is to disable SIP, make the changes in /bin , and then enable SIP again. Enabling and disabling SIP can be done according to the instructions here. It requires you to boot your machine into recovery mode and then use the csrutil disable and csrutil enable commands. It’s up to you if you want to go through this hassle to completely replace the old Bash version, or if you’re content with the two Bash versions living side by side.

Источник

Читайте также:  Gui для postgresql mac os
Оцените статью