When trying to create swift executable I get the following error

When I run

swift package init --type executable

I get the following error

Creating executable package: Hello
error: a manifest file already exists in this directory

No executable was created. I can't find the manifest file.

All I'm doing is follow the tutorial.


There should be = between type and executable instead of a space

@cukr I don’t think this is correct, you can use either of those.

@richardlamo if you use ls from terminal, there should be Package.swift file, which is the manifest. In order to create the executable, you need to type swift run. The executable will be located inside of .build/debug/ directory and will have the same name as your project (by default).

1 Like

Assuming you started with an empty directory...

# Create an empty directory.
mkdir -p ~/Desktop/I/want/to/put/it/here
# Go to that directory
cd ~/Desktop/I/want/to/put/it/here

...then doing this...

swift package init --type executable

...should succeed the first time, arranging some template source files as a package containing an executable.

But if you do a second time in the same place, then source files are already present, and it will object with the error you quoted, because it does not want to overwrite your work.

If you are certain you are in the directory you intended, and that you want to start over anew from a fresh template, then you will have to manually delete the directory’s contents† first. Once the directory is empty, the above command can be run again.

† Technically just the files relevant to the package description, but since you described yourself as a beginner, you have more pressing things to learn than which particular files are and are not relevant to this.

Just swift build. (swift run builds and then runs said executable.)

It will be at whatever path SwiftPM reports when you add --show-bin-path to the build invocation, which may or may not be .build/debug, depending on your configuration and the other options you supply to the build invocation.

The name comes from either the .executable(name: "whatever") product declaration (if vended), or from the .executableTarget(name: "whatever") target declaration (if hidden). The package name is irrelevant.

1 Like