# Switching Xcode versions without a password

DevFeed: [Switching Xcode versions without a password](<https://devfeed.tech/articles/switching-xcode-versions-without-a-password-25404.md>)

Original publisher: [Read original article](<https://smileykeith.com/2021/08/12/xcode-select-sudoers/>)

Author: Keith Smiley

Published: 2021-08-12T20:40:00Z

Content type: tutorial

Language: en

Sources: [Keith Smiley](<https://devfeed.tech/sources/keith-smiley.md>)

Topics: [Xcode](<https://devfeed.tech/topics/xcode.md>), [ci](<https://devfeed.tech/topics/ci.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [macOS](<https://devfeed.tech/topics/macos.md>), [passwords](<https://devfeed.tech/topics/passwords.md>), [Vim](<https://devfeed.tech/topics/vim.md>)

Tags: [ci](<https://devfeed.tech/tags/ci.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [macos](<https://devfeed.tech/tags/macos.md>), [password](<https://devfeed.tech/tags/password.md>), [vim](<https://devfeed.tech/tags/vim.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This tutorial explains how to switch between Xcode versions without entering a password. It configures sudoers on macOS so CI machines can run xcode-select and the restricted xcodebuild -runFirstLaunch command without password prompts, while keeping the custom rule in a separate sudoers.d file.

## Source excerpt

When switching between multiple Xcode versions one way to globally update the version you want to use is by running xcode-select like this: sudo xcode-select -s /Applications/Xcode-12.5.1.app Then, if you want to automatically accept Xcode's license, and install any extra packages it requires (which should only be required the for the first time you run a new version), you can run: sudo xcodebuild -runFirstLaunch This works fine locally, but when updating remote CI machines, entering the password can be troublesome. Furthermore if you want to support having CI machines automatically switch between Xcode versions when testing upcoming changes, you may not have the opportunity to be prompted at all. Lucky for us, the sudoers file format, which configures the sudo command, allows us to skip password entry for specific commands with a bit of configuration. The easiest way to edit this configuration is by running: sudo visudo This opens the default /etc/sudoers configuration file in vim. While we could add our custom configuration here, we can also see the default configuration that ships with macOS contains this line: #includedir /private/etc/sudoers.d This tells sudo to load all the files in /etc/sudoers.d1 as configuration as well. Using this knowledge we can nicely separate our custom configuration, making it easier to overwrite, or remove, in the future. Separating our custom configuration also makes us less likely to break the default configuration, potentially leading to major issues. To setup our custom configuration we can run this command: echo "%admin ALL=NOPASSWD: /usr/bin/xcode-select,/usr/bin/xcodebuild -runFirstLaunch" | sudo tee /etc/sudoers.d/xcode Let's break this down2. The %admin component makes this configuration apply to all users that are in the admin group3. Using this group is probably good enough for this use case, but if you'd like to restrict this more, you can change this to a your account's specific username such as ksmiley. The second compo