Installing the Solidity Compiler
Versioning
Solidity versions followsemantic versioning and in addition toreleases,nightly development builds are also made available. The nightly buildsare not guaranteed to be working and despite best efforts they might contain undocumentedand/or broken changes. We recommend using the latest release. Package installers belowwill use the latest release.
Remix
We recommend Remix for small contracts and for quickly learning Solidity.
Access Remix online, you do not need to install anything.If you want to use it without connection to the Internet, go tohttps://github.com/ethereum/remix-live/tree/gh-pages and download the.zip
file asexplained on that page. Remix is also a convenient option for testing nightly buildswithout installing multiple Solidity versions.
Further options on this page detail installing commandline Solidity compiler softwareon your computer. Choose a commandline compiler if you are working on a larger contractor if you require more compilation options.
npm / Node.js
Usenpm
for a convenient and portable way to installsolcjs
, a Solidity compiler. Thesolcjs program has fewer features than the ways to access the compiler describedfurther down this page. TheUsing the Commandline Compiler documentation assumes you are usingthe full-featured compiler,solc
. The usage ofsolcjs
is documented inside its ownrepository.
Note: The solc-js project is derived from the C++solc by using Emscripten which means that both use the same compiler source code.solc-js can be used in JavaScript projects directly (such as Remix).Please refer to the solc-js repository for instructions.
npm install -g solc
Note
The commandline executable is namedsolcjs
.
The commandline options ofsolcjs
are not compatible withsolc
and tools (such asgeth
)expecting the behaviour ofsolc
will not work withsolcjs
.
Docker
Docker images of Solidity builds are available using thesolc
image from theethereum
organisation.Use thestable
tag for the latest released version, andnightly
for potentially unstable changes in the develop branch.
The Docker image runs the compiler executable, so you can pass all compiler arguments to it.For example, the command below pulls the stable version of thesolc
image (if you do not have it already),and runs it in a new container, passing the--help
argument.
docker run ethereum/solc:stable --help
You can also specify release build versions in the tag, for example, for the 0.5.4 release.
docker run ethereum/solc:0.5.4 --help
To use the Docker image to compile Solidity files on the host machine mount alocal folder for input and output, and specify the contract to compile. For example.
docker run -v /local/path:/sources ethereum/solc:stable -o /sources/output --abi --bin /sources/Contract.sol
You can also use the standard JSON interface (which is recommended when using the compiler with tooling).When using this interface it is not necessary to mount any directories as long as the JSON input isself-contained (i.e. it does not refer to any external files that would have to beloaded by the import callback).
docker run ethereum/solc:stable --standard-json < input.json > output.json
Linux Packages
Binary packages of Solidity are available atsolidity/releases.
We also have PPAs for Ubuntu, you can get the latest stableversion using the following commands:
sudo add-apt-repository ppa:ethereum/ethereumsudo apt-get updatesudo apt-get install solc
The nightly version can be installed using these commands:
sudo add-apt-repository ppa:ethereum/ethereumsudo add-apt-repository ppa:ethereum/ethereum-devsudo apt-get updatesudo apt-get install solc
We are also releasing asnap package, which isinstallable in all thesupported Linux distros. Toinstall the latest stable version of solc:
sudo snap install solc
If you want to help testing the latest development version of Soliditywith the most recent changes, please use the following:
sudo snap install solc --edge
Note
Thesolc
snap uses strict confinement. This is the most secure mode for snap packagesbut it comes with limitations, like accessing only the files in your/home
and/media
directories.For more information, go toDemystifying Snap Confinement.
Arch Linux also has packages, albeit limited to the latest development version:
pacman -S solidity
Gentoo Linux has anEthereum overlay that contains a Solidity package.After the overlay is setup,solc
can be installed in x86_64 architectures by:
emerge dev-lang/solidity
macOS Packages
We distribute the Solidity compiler through Homebrewas a build-from-source version. Pre-built bottles arecurrently not supported.
brew updatebrew upgradebrew tap ethereum/ethereumbrew install solidity
To install the most recent 0.4.x / 0.5.x version of Solidity you can also usebrewinstallsolidity@4
andbrewinstallsolidity@5
, respectively.
If you need a specific version of Solidity you can install aHomebrew formula directly from Github.
Viewsolidity.rb commits on Github.
Copy the commit hash of the version you want and check it out on your machine.
git clone https://github.com/ethereum/homebrew-ethereum.gitcd homebrew-ethereumgit checkout <your-hash-goes-here>
Install it usingbrew
:
brew unlink solidity# eg. Install 0.4.8brew install solidity.rb
Static Binaries
We maintain a repository containing static builds of past and current compiler versions for allsupported platforms atsolc-bin. This is also the location where you can find the nightly builds.
The repository is not only a quick and easy way for end users to get binaries ready to be usedout-of-the-box but it is also meant to be friendly to third-party tools:
The content is mirrored tohttps://binaries.soliditylang.org where it can be easily downloaded overHTTPS without any authentication, rate limiting or the need to use git.
Content is served with correctContent-Type headers and lenient CORS configuration so that itcan be directly loaded by tools running in the browser.
Binaries do not require installation or unpacking (with the exception of older Windows buildsbundled with necessary DLLs).
We strive for a high level of backwards-compatibility. Files, once added, are not removed or movedwithout providing a symlink/redirect at the old location. They are also never modifiedin place and should always match the original checksum. The only exception would be broken orunusable files with a potential to cause more harm than good if left as is.
Files are served over both HTTP and HTTPS. As long as you obtain the file list in a secure way(via git, HTTPS, IPFS or just have it cached locally) and verify hashes of the binariesafter downloading them, you do not have to use HTTPS for the binaries themselves.
The same binaries are in most cases available on theSolidity release page on Github. Thedifference is that we do not generally update old releases on the Github release page. This meansthat we do not rename them if the naming convention changes and we do not add builds for platformsthat were not supported at the time of release. This only happens insolc-bin
.
Thesolc-bin
repository contains several top-level directories, each representing a single platform.Each one contains alist.json
file listing the available binaries. For example inemscripten-wasm32/list.json
you will find the following information about version 0.7.4:
{"path":"solc-emscripten-wasm32-v0.7.4+commit.3f05b770.js","version":"0.7.4","build":"commit.3f05b770","longVersion":"0.7.4+commit.3f05b770","keccak256":"0x300330ecd127756b824aa13e843cb1f43c473cb22eaf3750d5fb9c99279af8c3","sha256":"0x2b55ed5fec4d9625b6c7b3ab1abd2b7fb7dd2a9c68543bf0323db2c7e2d55af2","urls":["bzzr://16c5f09109c793db99fe35f037c6092b061bd39260ee7a677c8a97f18c955ab1","dweb:/ipfs/QmTLs5MuLEWXQkths41HiACoXDiH8zxyqBHGFDRSzVE5CS"]}
This means that:
You can find the binary in the same directory under the namesolc-emscripten-wasm32-v0.7.4+commit.3f05b770.js.Note that the file might be a symlink, and you will need to resolve it yourself if you are not usinggit to download it or your file system does not support symlinks.
The binary is also mirrored athttps://binaries.soliditylang.org/emscripten-wasm32/solc-emscripten-wasm32-v0.7.4+commit.3f05b770.js.In this case git is not necessary and symlinks are resolved transparently, either by serving a copyof the file or returning a HTTP redirect.
The file is also available on IPFS atQmTLs5MuLEWXQkths41HiACoXDiH8zxyqBHGFDRSzVE5CS.
The file might in future be available on Swarm at16c5f09109c793db99fe35f037c6092b061bd39260ee7a677c8a97f18c955ab1.
You can verify the integrity of the binary by comparing its keccak256 hash to
0x300330ecd127756b824aa13e843cb1f43c473cb22eaf3750d5fb9c99279af8c3
. The hash can be computedon the command line usingkeccak256sum
utility provided bysha3sum orkeccak256() functionfrom ethereumjs-util in JavaScript.You can also verify the integrity of the binary by comparing its sha256 hash to
0x2b55ed5fec4d9625b6c7b3ab1abd2b7fb7dd2a9c68543bf0323db2c7e2d55af2
.
Warning
Due to the strong backwards compatibility requirement the repository contains some legacy elementsbut you should avoid using them when writing new tools:
Use
emscripten-wasm32/
(with a fallback toemscripten-asmjs/
) instead ofbin/
ifyou want the best performance. Until version 0.6.1 we only provided asm.js binaries.Starting with 0.6.2 we switched toWebAssembly builds with much better performance. We haverebuilt the older versions for wasm but the original asm.js files remain inbin/
.The new ones had to be placed in a separate directory to avoid name clashes.Use
emscripten-asmjs/
andemscripten-wasm32/
instead ofbin/
andwasm/
directoriesif you want to be sure whether you are downloading a wasm or an asm.js binary.Use
list.json
instead oflist.js
andlist.txt
. The JSON list format contains allthe information from the old ones and more.Usehttps://binaries.soliditylang.org instead ofhttps://solc-bin.ethereum.org. To keep thingssimple we moved almost everything related to the compiler under the new
soliditylang.org
domain and this applies tosolc-bin
too. While the new domain is recommended, the old oneis still fully supported and guaranteed to point at the same location.
Warning
The binaries are also available athttps://ethereum.github.io/solc-bin/ but this pagestopped being updated just after the release of version 0.7.2, will not receive any new releasesor nightly builds for any platform and does not serve the new directory structure, includingnon-emscripten builds.
If you are using it, please switch tohttps://binaries.soliditylang.org, which is a drop-inreplacement. This allows us to make changes to the underlying hosting in a transparent way andminimize disruption. Unlike theethereum.github.io
domain, which we do not have any controlover,binaries.soliditylang.org
is guaranteed to work and maintain the same URL structurein the long-term.
Building from Source
Prerequisites - All Operating Systems
The following are dependencies for all builds of Solidity:
Software | Notes |
---|---|
CMake (version 3.13+) | Cross-platform build file generator. |
Boost (version 1.77+ onWindows, 1.65+ otherwise) | C++ libraries. |
Command-line tool for retrieving source code. | |
z3 (version 4.8+, Optional) | For use with SMT checker. |
cvc4 (Optional) | For use with SMT checker. |
Note
Solidity versions prior to 0.5.10 can fail to correctly link against Boost versions 1.70+.A possible workaround is to temporarily rename<Boostinstallpath>/lib/cmake/Boost-1.70.0
prior to running the cmake command to configure solidity.
Starting from 0.5.10 linking against Boost 1.70+ should work without manual intervention.
Minimum Compiler Versions
The following C++ compilers and their minimum versions can build the Solidity codebase:
Prerequisites - macOS
For macOS builds, ensure that you have the latest version ofXcode installed.This contains theClang C++ compiler, theXcode IDE and other Apple developmenttools that are required for building C++ applications on OS X.If you are installing Xcode for the first time, or have just installed a newversion then you will need to agree to the license before you can docommand-line builds:
sudo xcodebuild -license accept
Our OS X build script usesthe Homebrewpackage manager for installing external dependencies.Here’s how touninstall Homebrew,if you ever want to start again from scratch.
Prerequisites - Windows
You need to install the following dependencies for Windows builds of Solidity:
Software | Notes |
---|---|
C++ compiler | |
Visual Studio 2019 (Optional) | C++ compiler and dev environment. |
Boost (version 1.77+) | C++ libraries. |
If you already have one IDE and only need the compiler and libraries,you could install Visual Studio 2019 Build Tools.
Visual Studio 2019 provides both IDE and necessary compiler and libraries.So if you have not got an IDE and prefer to develop Solidity, Visual Studio 2019may be a choice for you to get everything setup easily.
Here is the list of components that should be installedin Visual Studio 2019 Build Tools or Visual Studio 2019:
Visual Studio C++ core features
VC++ 2019 v141 toolset (x86,x64)
Windows Universal CRT SDK
Windows 8.1 SDK
C++/CLI support
Dependencies Helper Script
We have a helper script which you can use to install all required external dependencieson macOS, Windows and on numerous Linux distros.
./scripts/install_deps.sh
Or, on Windows:
scripts\install_deps.ps1
Note that the latter command will installboost
andcmake
to thedeps
subdirectory, while the former commandwill attempt to install the dependencies globally.
Clone the Repository
To clone the source code, execute the following command:
git clone --recursive https://github.com/ethereum/solidity.gitcd solidity
If you want to help developing Solidity,you should fork Solidity and add your personal fork as a second remote:
git remote add personal git@github.com:[username]/solidity.git
Note
This method will result in a prerelease build leading to e.g. a flagbeing set in each bytecode produced by such a compiler.If you want to re-build a released Solidity compiler, thenplease use the source tarball on the github release page:
https://github.com/ethereum/solidity/releases/download/v0.X.Y/solidity_0.X.Y.tar.gz
(not the “Source code” provided by github).
Command-Line Build
Be sure to install External Dependencies (see above) before build.
Solidity project uses CMake to configure the build.You might want to installccache to speed up repeated builds.CMake will pick it up automatically.Building Solidity is quite similar on Linux, macOS and other Unices:
mkdir buildcd buildcmake ..&& make
or even easier on Linux and macOS, you can run:
#note: this will install binaries solc and soltest at usr/local/bin./scripts/build.sh
Warning
BSD builds should work, but are untested by the Solidity team.
And for Windows:
mkdir buildcd buildcmake -G"Visual Studio 16 2019" ..
In case you want to use the version of boost installed byscripts\install_deps.ps1
, you willadditionally need to pass-DBoost_DIR="deps\boost\lib\cmake\Boost-*"
and-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
as arguments to the call tocmake
.
This should result in the creation ofsolidity.sln in that build directory.Double-clicking on that file should result in Visual Studio firing up. We suggest buildingRelease configuration, but all others work.
Alternatively, you can build for Windows on the command-line, like so:
cmake --build . --config Release
CMake Options
If you are interested what CMake options are available runcmake..-LH
.
SMT Solvers
Solidity can be built against SMT solvers and will do so by default ifthey are found in the system. Each solver can be disabled by acmake option.
Note: In some cases, this can also be a potential workaround for build failures.
Inside the build folder you can disable them, since they are enabled by default:
# disables only Z3 SMT Solver.cmake .. -DUSE_Z3=OFF# disables only CVC4 SMT Solver.cmake .. -DUSE_CVC4=OFF# disables both Z3 and CVC4cmake .. -DUSE_CVC4=OFF -DUSE_Z3=OFF
The Version String in Detail
The Solidity version string contains four parts:
the version number
pre-release tag, usually set to
develop.YYYY.MM.DD
ornightly.YYYY.MM.DD
commit in the format of
commit.GITHASH
platform, which has an arbitrary number of items, containing details about the platform and compiler
If there are local modifications, the commit will be postfixed with.mod
.
These parts are combined as required by Semver, where the Solidity pre-release tag equals to the Semver pre-releaseand the Solidity commit and platform combined make up the Semver build metadata.
A release example:0.4.8+commit.60cc1668.Emscripten.clang
.
A pre-release example:0.4.9-nightly.2017.1.17+commit.6ecb4aa3.Emscripten.clang
Important Information About Versioning
After a release is made, the patch version level is bumped, because we assume that onlypatch level changes follow. When changes are merged, the version should be bumped accordingto semver and the severity of the change. Finally, a release is always made with the versionof the current nightly build, but without theprerelease
specifier.
Example:
The 0.4.0 release is made.
The nightly build has a version of 0.4.1 from now on.
Non-breaking changes are introduced –> no change in version.
A breaking change is introduced –> version is bumped to 0.5.0.
The 0.5.0 release is made.
This behaviour works well with theversion pragma.