In this tutorial we show how to install the Solidity compiler on MacOS, check the installed version, get help to learn about available options and compile a smart contract written in Solidity.
Install Solidity on MacOS
To install Solidity on MacOS we can use Homebrew. This provides us with build-from-source macOS packages and we just have to follow the installation process.
brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity
After the execution finished we can check that Solidity is successfully installed by querying for the version.
solc --version
and receive the installed Solidity version as response. If the installation wasn't successful the command above will not execute.
solc, the solidity compiler commandline interface
Version: 0.8.9+commit.e5eed63a.Darwin.appleclang
Install specific Solidity version
It is also possible to install a specific Solidity version by selecting the hash on the homebrew-ethereum depository on github and then pasting it into the following code:
git clone https://github.com/ethereum/homebrew-ethereum.git
cd homebrew-ethereum
git checkout [INSERT_HASH_HERE]
and then running the installation:
brew unlink solidity
brew install solidity.rb
check version of Solidity
To check for the version of the installed Solidity compiler we can always run the following command in the command-line interface.
solc --version
and the installed version is returned:
solc, the solidity compiler command-line interface
Version: 0.8.9+commit.e5eed63a.Darwin.appleclang
help for
To get help and learn about the available options in solc, we can use the help:
solc --help
compile a contract
To compile a contract we can run:
solc contract.sol
and to specify a specifc EVM-version to compile for we can set the version:
solc --evm-version [EVM-VERSION] contract.sol