12

I'm trying to use solc with no success.

I download solc with npm install solc but when I run solc --version the console output is:

command not found.

If I list packages npm list I'm able to see [email protected].

What's wrong?

1

9 Answers 9

4

You should add solc to PATH. Type which solc to get the location where the solidity compiler is installed and add this to PATH. If you just want to check the version, navigate to the location where solidity is installed and then type in the command solc --version.

8
  • no output with which solc I try also npm install -g solc
    – underdog
    Jun 20, 2016 at 19:37
  • What result did you get for the which solc command?
    – galahad
    Jun 20, 2016 at 19:40
  • nothing pippo-MacBook-Pro:~ pippo$ which solc pippo-MacBook-Pro:~ pippo$
    – underdog
    Jun 20, 2016 at 19:45
  • Try this and check if it works.
    – galahad
    Jun 20, 2016 at 19:47
  • Now it seems to be ok. I download cpp-ethereum end in geth console set for admin.setSolc() the output of which solc. So, solc always require cpp-ethereum, is not stand-alone?
    – underdog
    Jun 20, 2016 at 20:00
19

If you have installed through npm install -g solc

Here's how you use it. solcjs --version

2
  • doesn't say what's wrong, which is that without -g the command is not installed in the user's path. The other solution is for the user to update their path. This is really an npm issue...
    – Paul S
    Sep 20, 2016 at 18:22
  • Kind of annoying... Can I have my 15 minutes back? Surely you install solc and then run solcjs... Please. Nov 25, 2017 at 11:13
3

install solc compiler using

npm install -g solc

it install compiler in global scope and use from any location.

To check version of installed compiler

solcjs --version

is return something like "0.4.23+commit.124ca40d.Emscripten.clang"

more details are available here.

2

npm install solc currently does not install a globally available compiler. The solc npm package are just Javascript bindings to use in a Javascript module.

After struggling with this myself for some time, there currently seems to be no convenient way to install a standalone Solidity compiler, at least on Mac OS X.

1

Expanding on @graup, I've reinstalled solc from my contracts directory of each new contract project, which has worked for me:

cd contracts
npm install solc
npm install ethereumjs-testrpc [email protected]

node

Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

code = fs.readFileSync('MyContrat.sol').toString()
solc = require('solc')
compileCode = solc.compile(code)
0

npm i solc@version

By using this command you can do the installation of your required version solidity.

0

Just do:

solcjs --version

And even when compiling do solcjs.

0

Had similar issue after installing globally, but npx solc --version fetched the version

1
0

Here is how you can add to path if you have installed via python3 using pip3!

export PATH=$PATH:/Users/nolanjacobson/Library/Python/3.8/bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.