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 solc@0.3.5.

What's wrong?

q9f
  • 32,913
  • 47
  • 156
  • 395
underdog
  • 1,190
  • 2
  • 12
  • 24

9 Answers9

19

If you have installed through npm install -g solc

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

Sorter
  • 291
  • 2
  • 5
  • 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 '16 at 18:22
  • Kind of annoying... Can I have my 15 minutes back? Surely you install solc and then run solcjs... Please. – Mars Robertson Nov 25 '17 at 11:13
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.

galahad
  • 3,920
  • 3
  • 26
  • 66
  • no output with which solc

    I try also npm install -g solc

    – underdog Jun 20 '16 at 19:37
  • What result did you get for the which solc command? – galahad Jun 20 '16 at 19:40
  • nothing

    pippo-MacBook-Pro:~ pippo$ which solc pippo-MacBook-Pro:~ pippo$

    – underdog Jun 20 '16 at 19:45
  • Try this and check if it works. – galahad Jun 20 '16 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 '16 at 20:00
  • Solidity doesn't require an ethereum client. A stand-alone version can be installed to develop and test smart contracts. But it is a built-in feature in the official Ethereum clients. Check this for more details. – galahad Jun 20 '16 at 20:07
  • Ok, but with npm install solc ** --version** doesn't output nothing, which solc too, why? Tks for response – underdog Jun 20 '16 at 20:10
  • This is not a good answer. It doesn't address why npm install solc doesn't install a global solc tool, or how to install a compiler instead. – graup Jul 17 '16 at 22:17
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.

manendra
  • 31
  • 1
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.

graup
  • 463
  • 3
  • 12
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 web3@0.20.1

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)
Jazzmine
  • 187
  • 1
  • 12
0

Just do:

solcjs --version

And even when compiling do solcjs.

Amar Shukla
  • 101
  • 1
0

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

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

0

npm i solc@version

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

Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82