Install Solidity On Linux
In this article, You will learn how to Install Solidity and set up a compiler on a CentOS machine. In the case that you do not have a Linux machine, you can use Solidity Online Compiler for small contracts and for gaining a quick understanding of the language.
If you want to develop decentralized applications (dApps) on the Ethereum platform, you need to install Solidity on your Linux system. we will show you how to install Solidity on Linux using various methods.
Method 1 – npm / Node.js
Using this method, you will be able to install the Solidity compiler on your CentOS machine as fast as possible.
Solidity Compiler can be installed by following these steps:
Install Node.js
The first thing you need to do is make sure you have Node.js installed on your CentOS machine.
Use the following commands to install it, if it’s not already installed:
Launch your CentOS machine’s terminal window.
Using the following command, you can install Node.js and npm on your machine:
sudo yum install -y nodejs
Run the following command to install the Solidity compiler module globally:
sudo npm install -g solc
The following command will verify that the Solidity compiler has been installed:
solcjs --version
This should output the version of the Solidity compiler installed on your machine.
It’s done! Solidity is now installed via npm on your CentOS machine and ready for use.
Solidity code can be compiled with the solcjs command.
You should see an output like this if everything has been installed
Install solc
As soon as Node.js package manager is installed, you can proceed to installing Solidity compiler as follows:
$sudonpm install -g solc
Using the above command, Solcjs will be installed and made available globally throughout the system.
The following command will test your Solidity compiler:
$solcjs-version
In the case that everything goes according to plan, then this will print as follows:
The solidity compiler provides fewer features than solcjs, but it will serve as a good starting point for solidity programs.
Method 2 Docker Image
You can pull a Docker image and start using it to start with Solidity programming.
Following are the simple steps. Following is the command to pull a Solidity Docker Image.
$docker pull ethereum/solc:stable
The following command can be used to verify a docker image after it has been downloaded.
$docker run ethereum/solc:stable-version
As a result, something will appear as follows: −
$ docker run ethereum/solc:stable -version
solc, the solidity compiler commandlineinterfaceVersion: 0.5.2+commit.1df8f40c.Linux.g++
Method 3 Binary Packages Installation
Another way to install Solidity on Linux is by downloading the binary packages from the Solidity GitHub repository.
This method is useful if you want to install a specific version of Solidity or if your Linux distribution doesn’t have an official package for Solidity.
In this method, we will show you how to install Solidity on Ubuntu.
Step 1: Download the binary package
wget https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux
Step 2: Give it an executable permission
chmod +x ~/solc-static-linux
Method 4 Snap
Snap is a package manager for Linux that allows you to install packages as self-contained applications.
Solidity is available on snap as well. In this method, we will show you how to install Solidity using snap on Ubuntu.
Step 1: Update the package index
sudo apt-get update
Step 2: Install Snap
sudo apt-get install snapd
Step 3: Install Solidity using Snap
sudo snap install solc
Now verify your installation
solc --version
This command will print the version of Solidity that you have installed.
If it prints the version number, then Solidity is successfully installed on your system.
Conclusion
In this article, we have shown you Four methods to install Solidity on Linux.
You can choose the method that suits your needs and requirements.
If you are new to Solidity and Ethereum development, we recommend using the package manager or snap to install the latest version of Solidity available in your distribution’s repository.
If you are an experienced developer and need to use a specific version of Solidity, you can download the binary package and install it on your system.