Flutter command to delete packages in .pub-cache folder
Solution 1
If a dependency is removed from the pubspec and then pub get
is run, it removes the dependency from the .packages file, making the dependency unavailable for importing.
If a packages in your pub cache to change or break, you can use flutter pub cache repair
command performs a clean reinstall of all hosted and git packages in the system cache.
Solution 2
To clear the global PUB_CACHE, run:
dart pub cache clean
or
flutter pub cache clean
Solution 3
Short answer
Delete the pubspec.lock
file then run the command flutter pub get
again.
Long Story
- the command
flutter pub get
will regenerate thepubspec.lock
. - In case your code isn't tracked by a source code version control like
git
, make sure to take a backup copy from yourpubspec.lock
file before deleting it especially if the project is a bit old and you are usingcaret constraint
for package depencedy and not usingconcrete versions
inpubspec.ymal
- if the project didn't compile after applying the answer it could be
caret constraint
issue so you have to update your project to match the new library version or useconcrete versions
inpubspec.ymal
for example
dependencies:
path: 1.3.0
Solution 4
Just go to the terminal and type the command
flutter pub remove package_name
as like
flutter pub remove flutter_riverpod
Solution 5
It took me more than 3 days to try all differently way. But finally I found, you need to go into the "pubspec.lock" file. Then go to the library and change the version there. Then go back to the file "pubspec.yaml" and run Packages get and it succeeds.
Dharanidharan
Updated on October 07, 2021Comments
-
Dharanidharan over 2 years
How to delete the flutter packages in
.pub-cache
folder? When we giveflutter clean
, it will delete the build folder in the current directory. We can delete it manually, but my requirement is to delete the packages in.pub-cache
folder using the command. -
Mohammed Noureldin almost 3 yearsThis file should be pushed to the source control, how should removing it be a good solution?
-
Shady Mohamed Sherif almost 3 yearsThe command
flutter pub get
will regenerate that file again, don't worry -
Mohammed Noureldin almost 3 yearsThen what is the purpose of checking this file to the source control? Something does not make sense in that.
-
Shady Mohamed Sherif almost 3 yearsKeeping
pubspec.lock
in source control is optional but; It would be helpful if the project is a bit old and you are usingcaret constraint
for package depencedy and not usingconcrete versions
inpubspec.ymal
which would cause other developers to get newer versions in thepubspec.lock
which may cause compilation issues. -
Mohammed Noureldin almost 3 yearsAah ok, that makes sense now, thanks Shady! But nevertheless, I may end up getting a newer version if I use the
caret
, which will encourage me to not remove this file :D -
Shady Mohamed Sherif almost 3 yearsYou are welcome, Yes you are right; that's why you may need to keep a backup from your original
pubspec.lock
before you delete it if it isn't tracked by a source code version control :D I will add it as a note in the answer. -
masaya almost 3 yearsThis command was added in Dart 2.14.0 github.com/dart-lang/sdk/blob/master/CHANGELOG.md
-
Thong M Truong over 2 years
flutter pub cache clean
also works -
CopsOnRoad over 2 years@ThongMTruong Yeah, most Dart commands work with Flutter tools also.
-
kokemomuke over 2 yearsthis answer should be marked as correct!